Server: Vacuum database on startup

Runs after the migrations. In some cases, it can reclaim a significant amount of space (reported 30%).
This commit is contained in:
Saverio Miroddi 2022-08-10 21:41:29 +02:00
parent 5e5665ea19
commit 021a8be62e
3 changed files with 17 additions and 0 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Currently playing music track and artist now shows in the debug menu.
- Added a setting to influence the gap between music track plays.
- Added a Craft All button.
- Server: Vacuum database on startup
### Changed
- Use fluent for translations

View File

@ -230,6 +230,10 @@ impl Server {
debug!("Running DB migrations...");
persistence::run_migrations(&database_settings);
// Vacuum database
debug!("Vacuuming database...");
persistence::vacuum_database(&database_settings);
let database_settings = Arc::new(RwLock::new(database_settings));
let registry = Arc::new(Registry::new());

View File

@ -172,6 +172,18 @@ pub fn run_migrations(settings: &DatabaseSettings) {
info!("Applied {} database migrations", applied_migrations);
}
/// Runs after the migrations. In some cases, it can reclaim a significant
/// amount of space (reported 30%)
pub fn vacuum_database(settings: &DatabaseSettings) {
let conn = establish_connection(settings, ConnectionMode::ReadWrite);
// The params type is phony; it's required, but not meaningful.
conn.execute::<&[u32]>("VACUUM main", &[])
.expect("Database vacuuming failed, server startup aborted");
info!("Database vacuumed");
}
// These callbacks use info logging because they are never enabled by default,
// only when explicitly turned on via CLI arguments or interactive CLI commands.
// Setting them to anything other than info would remove the ability to get SQL