mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-05 14:35:20 -04:00
fix(sqlite): Use a prepared statement to insert events.
This patch uses a prepared statement to insert events in the linked chunks. It offers more predictable performance, and SQLite prefers that.
This commit is contained in:
@@ -486,10 +486,19 @@ impl EventCacheStore for SqliteEventCacheStore {
|
||||
}
|
||||
|
||||
Update::PushItems { at, items } => {
|
||||
if items.is_empty() {
|
||||
// Should never happens, but better be safe.
|
||||
continue;
|
||||
}
|
||||
|
||||
let chunk_id = at.chunk_identifier().index();
|
||||
|
||||
trace!(%room_id, "pushing {} items @ {chunk_id}", items.len());
|
||||
|
||||
let mut statement = txn.prepare(
|
||||
"INSERT INTO events(chunk_id, room_id, event_id, content, position) VALUES (?, ?, ?, ?, ?)"
|
||||
)?;
|
||||
|
||||
for (i, event) in items.into_iter().enumerate() {
|
||||
let serialized = serde_json::to_vec(&event)?;
|
||||
let content = this.encode_value(serialized)?;
|
||||
@@ -497,13 +506,7 @@ impl EventCacheStore for SqliteEventCacheStore {
|
||||
let event_id = event.event_id().map(|event_id| event_id.to_string());
|
||||
let index = at.index() + i;
|
||||
|
||||
txn.execute(
|
||||
r#"
|
||||
INSERT INTO events(chunk_id, room_id, event_id, content, position)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
"#,
|
||||
(chunk_id, &hashed_room_id, event_id, content, index),
|
||||
)?;
|
||||
statement.execute((chunk_id, &hashed_room_id, event_id, content, index))?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user