fix(sqlite): Empty the cache after the introduction of TimelineEvent::timestamp.

After the merge of
https://github.com/matrix-org/matrix-rust-sdk/pull/5648, we want
all events to get a `TimelineEvent::timestamp` value (extracted from
`origin_server_ts`).

To accomplish that, we are emptying the event cache. New synced events
will be built correctly, with a valid `TimelineEvent::timestamp`,
allowing a clear, stable situation.
This commit is contained in:
Ivan Enderlin
2025-09-12 14:13:18 +02:00
parent c2bc465c06
commit 5ccbc1c378
2 changed files with 23 additions and 1 deletions

View File

@@ -0,0 +1,12 @@
-- After the merge of https://github.com/matrix-org/matrix-rust-sdk/pull/5648,
-- we want all events to get a `TimelineEvent::timestamp` value (extracted from
-- `origin_server_ts`).
--
-- To accomplish that, we are emptying the event cache. New synced events will
-- be built correctly, with a valid `TimelineEvent::timestamp`, allowing a
-- clear, stable situation.
DELETE from linked_chunks;
DELETE from event_chunks; -- should be done by cascading
DELETE from gap_chunks; -- should be done by cascading
DELETE from events;

View File

@@ -63,7 +63,7 @@ const DATABASE_NAME: &str = "matrix-sdk-event-cache.sqlite3";
/// This is used to figure whether the SQLite database requires a migration.
/// Every new SQL migration should imply a bump of this number, and changes in
/// the [`run_migrations`] function.
const DATABASE_VERSION: u8 = 10;
const DATABASE_VERSION: u8 = 11;
/// The string used to identify a chunk of type events, in the `type` field in
/// the database.
@@ -453,6 +453,16 @@ async fn run_migrations(conn: &SqliteAsyncConn, version: u8) -> Result<()> {
}
}
if version < 11 {
conn.with_transaction(|txn| {
txn.execute_batch(include_str!(
"../migrations/event_cache_store/011_empty_event_cache.sql"
))?;
txn.set_db_version(11)
})
.await?;
}
Ok(())
}