@@ -298,7 +298,7 @@ impl TransactionExtForLinkedChunks for Transaction<'_> {
298
298
// There's at most one row for it in the database, so a call to `query_row` is
299
299
// sufficient.
300
300
let encoded_prev_token: Vec < u8 > = self . query_row (
301
- "SELECT prev_token FROM gaps WHERE chunk_id = ? AND room_id = ?" ,
301
+ "SELECT prev_token FROM gap_chunks WHERE chunk_id = ? AND room_id = ?" ,
302
302
( chunk_id. index ( ) , & room_id) ,
303
303
|row| row. get ( 0 ) ,
304
304
) ?;
@@ -319,8 +319,8 @@ impl TransactionExtForLinkedChunks for Transaction<'_> {
319
319
for event_data in self
320
320
. prepare (
321
321
r#"
322
- SELECT content
323
- FROM events_chunks ec
322
+ SELECT events. content
323
+ FROM event_chunks ec
324
324
INNER JOIN events USING (event_id, room_id)
325
325
WHERE ec.chunk_id = ? AND ec.room_id = ?
326
326
ORDER BY ec.position ASC
@@ -410,7 +410,7 @@ async fn run_migrations(conn: &SqliteAsyncConn, version: u8) -> Result<()> {
410
410
if version < 7 {
411
411
conn. with_transaction ( |txn| {
412
412
txn. execute_batch ( include_str ! (
413
- "../migrations/event_cache_store/007_events_chunks .sql"
413
+ "../migrations/event_cache_store/007_event_chunks .sql"
414
414
) ) ?;
415
415
txn. set_db_version ( 7 )
416
416
} )
@@ -517,7 +517,7 @@ impl EventCacheStore for SqliteEventCacheStore {
517
517
// Insert the gap's value.
518
518
txn. execute (
519
519
r#"
520
- INSERT INTO gaps (chunk_id, room_id, prev_token)
520
+ INSERT INTO gap_chunks (chunk_id, room_id, prev_token)
521
521
VALUES (?, ?, ?)
522
522
"# ,
523
523
( new, & hashed_room_id, prev_token) ,
@@ -562,12 +562,13 @@ impl EventCacheStore for SqliteEventCacheStore {
562
562
trace ! ( %room_id, "pushing {} items @ {chunk_id}" , items. len( ) ) ;
563
563
564
564
let mut chunk_statement = txn. prepare (
565
- "INSERT INTO events_chunks (chunk_id, room_id, event_id, position) VALUES (?, ?, ?, ?)"
565
+ "INSERT INTO event_chunks (chunk_id, room_id, event_id, position) VALUES (?, ?, ?, ?)"
566
566
) ?;
567
567
568
568
// Note: we use `OR REPLACE` here, because the event might have been
569
569
// already inserted in the database. This is the case when an event is
570
- // deduplicated and moved to another position.
570
+ // deduplicated and moved to another position; or because it was inserted
571
+ // outside the context of a linked chunk (e.g. pinned event).
571
572
let mut content_statement = txn. prepare (
572
573
"INSERT OR REPLACE INTO events(room_id, event_id, content, relates_to, rel_type) VALUES (?, ?, ?, ?, ?)"
573
574
) ?;
@@ -615,7 +616,7 @@ impl EventCacheStore for SqliteEventCacheStore {
615
616
616
617
// Replace the event id in the linked chunk, in case it changed.
617
618
txn. execute (
618
- r#"UPDATE events_chunks SET event_id = ? WHERE room_id = ? AND chunk_id = ? AND position = ?"# ,
619
+ r#"UPDATE event_chunks SET event_id = ? WHERE room_id = ? AND chunk_id = ? AND position = ?"# ,
619
620
( event_id, & hashed_room_id, chunk_id, index)
620
621
) ?;
621
622
}
@@ -627,12 +628,12 @@ impl EventCacheStore for SqliteEventCacheStore {
627
628
trace ! ( %room_id, "removing item @ {chunk_id}:{index}" ) ;
628
629
629
630
// Remove the entry in the chunk table.
630
- txn. execute ( "DELETE FROM events_chunks WHERE room_id = ? AND chunk_id = ? AND position = ?" , ( & hashed_room_id, chunk_id, index) ) ?;
631
+ txn. execute ( "DELETE FROM event_chunks WHERE room_id = ? AND chunk_id = ? AND position = ?" , ( & hashed_room_id, chunk_id, index) ) ?;
631
632
632
633
// Decrement the index of each item after the one we're going to remove.
633
634
txn. execute (
634
635
r#"
635
- UPDATE events_chunks
636
+ UPDATE event_chunks
636
637
SET position = position - 1
637
638
WHERE room_id = ? AND chunk_id = ? AND position > ?
638
639
"# ,
@@ -648,7 +649,7 @@ impl EventCacheStore for SqliteEventCacheStore {
648
649
trace ! ( %room_id, "truncating items >= {chunk_id}:{index}" ) ;
649
650
650
651
// Remove these entries.
651
- txn. execute ( "DELETE FROM events_chunks WHERE room_id = ? AND chunk_id = ? AND position >= ?" , ( & hashed_room_id, chunk_id, index) ) ?;
652
+ txn. execute ( "DELETE FROM event_chunks WHERE room_id = ? AND chunk_id = ? AND position >= ?" , ( & hashed_room_id, chunk_id, index) ) ?;
652
653
}
653
654
654
655
Update :: Clear => {
@@ -894,7 +895,7 @@ impl EventCacheStore for SqliteEventCacheStore {
894
895
let query = format ! (
895
896
r#"
896
897
SELECT event_id, chunk_id, position
897
- FROM events_chunks
898
+ FROM event_chunks
898
899
WHERE room_id = ? AND event_id IN ({})
899
900
ORDER BY chunk_id ASC, position ASC
900
901
"# ,
@@ -999,7 +1000,7 @@ impl EventCacheStore for SqliteEventCacheStore {
999
1000
. into_iter( )
1000
1001
. map( |f| format!( r#""{f}""# ) )
1001
1002
. collect:: <Vec <_>>( )
1002
- . join( r# ", "# )
1003
+ . join( ", " )
1003
1004
)
1004
1005
} else {
1005
1006
"" . to_owned ( )
@@ -1825,7 +1826,7 @@ mod tests {
1825
1826
. with_transaction ( |txn| -> rusqlite:: Result < _ > {
1826
1827
let mut gaps = Vec :: new ( ) ;
1827
1828
for data in txn
1828
- . prepare ( "SELECT chunk_id FROM gaps ORDER BY chunk_id" ) ?
1829
+ . prepare ( "SELECT chunk_id FROM gap_chunks ORDER BY chunk_id" ) ?
1829
1830
. query_map ( ( ) , |row| row. get :: < _ , u64 > ( 0 ) ) ?
1830
1831
{
1831
1832
gaps. push ( data?) ;
@@ -1934,7 +1935,7 @@ mod tests {
1934
1935
. unwrap ( )
1935
1936
. with_transaction ( move |txn| {
1936
1937
txn. query_row (
1937
- "SELECT COUNT(*) FROM events_chunks WHERE chunk_id = 42 AND room_id = ? AND position = 0" ,
1938
+ "SELECT COUNT(*) FROM event_chunks WHERE chunk_id = 42 AND room_id = ? AND position = 0" ,
1938
1939
( room_id. as_bytes ( ) , ) ,
1939
1940
|row| row. get ( 0 ) ,
1940
1941
)
@@ -2080,12 +2081,12 @@ mod tests {
2080
2081
. unwrap ( )
2081
2082
. with_transaction ( |txn| -> rusqlite:: Result < _ > {
2082
2083
let num_gaps = txn
2083
- . prepare ( "SELECT COUNT(chunk_id) FROM gaps ORDER BY chunk_id" ) ?
2084
+ . prepare ( "SELECT COUNT(chunk_id) FROM gap_chunks ORDER BY chunk_id" ) ?
2084
2085
. query_row ( ( ) , |row| row. get :: < _ , u64 > ( 0 ) ) ?;
2085
2086
assert_eq ! ( num_gaps, 0 ) ;
2086
2087
2087
2088
let num_events = txn
2088
- . prepare ( "SELECT COUNT(event_id) FROM events_chunks ORDER BY chunk_id" ) ?
2089
+ . prepare ( "SELECT COUNT(event_id) FROM event_chunks ORDER BY chunk_id" ) ?
2089
2090
. query_row ( ( ) , |row| row. get :: < _ , u64 > ( 0 ) ) ?;
2090
2091
assert_eq ! ( num_events, 0 ) ;
2091
2092
0 commit comments