From 89dcda4c3c723afa43480e8ceb98185fe059c653 Mon Sep 17 00:00:00 2001 From: Ginger Date: Thu, 9 Jul 2026 16:43:10 -0400 Subject: [PATCH] feat: Kill roomsynctoken_shortstatehash dead --- changelog.d/917.bugfix.md | 2 +- src/database/engine.rs | 8 +++++++- src/service/migrations.rs | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/changelog.d/917.bugfix.md b/changelog.d/917.bugfix.md index 82dbaec18..ce9b1b99e 100644 --- a/changelog.d/917.bugfix.md +++ b/changelog.d/917.bugfix.md @@ -1 +1 @@ -Adjusted legacy sync logic to no longer use the `roomsynctoken_shortstatehash` database column. Once this change has been confirmed to be stable and reliable, a future update will remove it entirely, significantly decreasing database sizes. Contributed by @ginger. +Adjusted legacy sync logic to allow the `roomsynctoken_shortstatehash` database column to be dropped, massively reducing database sizes, especially for old deployments. Contributed by @ginger. diff --git a/src/database/engine.rs b/src/database/engine.rs index 45973d08f..a0a99ad60 100644 --- a/src/database/engine.rs +++ b/src/database/engine.rs @@ -17,7 +17,7 @@ }, }; -use conduwuit::{Err, Result, debug, info, warn}; +use conduwuit::{Err, Result, debug, err, info, warn}; use rocksdb::{ AsColumnFamilyRef, BoundColumnFamily, DBCommon, DBWithThreadMode, MultiThreaded, WaitForCompactOptions, @@ -127,6 +127,12 @@ pub fn current_sequence(&self) -> u64 { sequence } + + pub fn drop_column(&self, name: &str) -> Result { + self.db + .drop_cf(name) + .map_err(|err| err!("Failed to drop {name}: {err}")) + } } impl Drop for Engine { diff --git a/src/service/migrations.rs b/src/service/migrations.rs index 780c52263..8eb996a68 100644 --- a/src/service/migrations.rs +++ b/src/service/migrations.rs @@ -240,6 +240,19 @@ async fn migrate(services: &Services) -> Result<()> { .map_err(|e| err!("Failed to run 'split_userid_password' migration': {e}"))?; } + if db["global"] + .get(DROP_ROOMSYNCTOKEN_SHORTSTATEHASH) + .await + .is_not_found() + { + info!("Running migration 'drop_roomsynctoken_shortstatehash'"); + obliterate_roomsynctoken_shortstatehash_with_extreme_prejudice(services) + .await + .map_err(|e| { + err!("Failed to run 'drop_roomsynctoken_shortstatehash' migration': {e}") + })?; + } + assert_eq!( services.globals.db.database_version().await, DATABASE_VERSION, @@ -873,3 +886,14 @@ async fn split_userid_password(services: &Services) -> Result { db.db.sort()?; Ok(()) } + +const DROP_ROOMSYNCTOKEN_SHORTSTATEHASH: &str = "drop_roomsynctoken_shortstatehash"; +async fn obliterate_roomsynctoken_shortstatehash_with_extreme_prejudice( + services: &Services, +) -> Result { + services.db.db.drop_column("roomsynctoken_shortstatehash")?; + + info!("Cleared roomsynctoken_shortstatehash."); + + Ok(()) +}