Skip to content

Commit 5ccbc1c

Browse files
committed
fix(sqlite): Empty the cache after the introduction of TimelineEvent::timestamp.
After the merge of #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.
1 parent c2bc465 commit 5ccbc1c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- After the merge of https://github.com/matrix-org/matrix-rust-sdk/pull/5648,
2+
-- we want all events to get a `TimelineEvent::timestamp` value (extracted from
3+
-- `origin_server_ts`).
4+
--
5+
-- To accomplish that, we are emptying the event cache. New synced events will
6+
-- be built correctly, with a valid `TimelineEvent::timestamp`, allowing a
7+
-- clear, stable situation.
8+
9+
DELETE from linked_chunks;
10+
DELETE from event_chunks; -- should be done by cascading
11+
DELETE from gap_chunks; -- should be done by cascading
12+
DELETE from events;

crates/matrix-sdk-sqlite/src/event_cache_store.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const DATABASE_NAME: &str = "matrix-sdk-event-cache.sqlite3";
6363
/// This is used to figure whether the SQLite database requires a migration.
6464
/// Every new SQL migration should imply a bump of this number, and changes in
6565
/// the [`run_migrations`] function.
66-
const DATABASE_VERSION: u8 = 10;
66+
const DATABASE_VERSION: u8 = 11;
6767

6868
/// The string used to identify a chunk of type events, in the `type` field in
6969
/// the database.
@@ -453,6 +453,16 @@ async fn run_migrations(conn: &SqliteAsyncConn, version: u8) -> Result<()> {
453453
}
454454
}
455455

456+
if version < 11 {
457+
conn.with_transaction(|txn| {
458+
txn.execute_batch(include_str!(
459+
"../migrations/event_cache_store/011_empty_event_cache.sql"
460+
))?;
461+
txn.set_db_version(11)
462+
})
463+
.await?;
464+
}
465+
456466
Ok(())
457467
}
458468

0 commit comments

Comments
 (0)