Skip to content

Commit 6057b40

Browse files
authored
fix: Clear the config cache after every migration (#6438)
Some migrations change the `config` table, but they don't update the cache. While this wasn't the cause for #6432, it might have caused a similar bug, so, let's clear the config cache after every migration.
1 parent 53572fc commit 6057b40

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/sql/migrations.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,35 @@ impl Sql {
12311231
.await
12321232
.with_context(|| format!("execute_migration failed for version {version}"))?;
12331233

1234-
self.set_db_version_in_cache(version).await
1234+
self.config_cache.write().await.clear();
1235+
1236+
Ok(())
1237+
}
1238+
}
1239+
1240+
#[cfg(test)]
1241+
mod tests {
1242+
use super::*;
1243+
use crate::config::Config;
1244+
use crate::test_utils::TestContext;
1245+
1246+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1247+
async fn test_clear_config_cache() -> anyhow::Result<()> {
1248+
// Some migrations change the `config` table in SQL.
1249+
// This test checks that the config cache is invalidated in `execute_migration()`.
1250+
1251+
let t = TestContext::new().await;
1252+
assert_eq!(t.get_config_bool(Config::IsChatmail).await?, false);
1253+
1254+
t.sql
1255+
.execute_migration(
1256+
"INSERT INTO config (keyname, value) VALUES ('is_chatmail', '1')",
1257+
1000,
1258+
)
1259+
.await?;
1260+
assert_eq!(t.get_config_bool(Config::IsChatmail).await?, true);
1261+
assert_eq!(t.sql.get_raw_config_int(VERSION_CFG).await?.unwrap(), 1000);
1262+
1263+
Ok(())
12351264
}
12361265
}

0 commit comments

Comments
 (0)