feat: implement database vacuuming. #2931
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change attempts to resolve #2927 by introducing the ability to VACUUM the database by:
giving atuin-server-database the
vacuummethod. This simply callssqlx::query("VACUUM"). I also added a test, as we're using sqlx & sqlite this test can be executed in memory. Sadly the same cannot happen for postgres, but the test is kind of trivial.exposing a vacuum endpoint on the server. This handler calls vacuum. This can be useful for users who wish to manually vacuum a db, but this is not exposed via the CLI, instead...
adding
auto_vacuum_thresholdoption to the server configuration.auto_vacuum_thresholdis > 0, then the server will increment thedelete_countatomic counter, and when this counter reached the threshold it will call vacuum and reset the counter.The default for
auto_vacuum_thresholdis0meaning "never vacuum", but users can set this to a value which will come down to their preference, guided by:How long they anticipate their server running for. For example setting it to a high-ish number like 1000 would probably be appropriate for a server running on a machine which has long uptimes. For self hosting for a single user, this might be a little long though, keeping in mind that if the server goes down (or the mahcine goes down) the counter will reset to 0.
For users who really care about disk space and don't really care about latency on deletes, setting to
1will will vacuum on every delete.I considered adding some kind of "recommended" number but I don't think there is a good number to unilaterally recommend for this.