File tree Expand file tree Collapse file tree 3 files changed +36
-4
lines changed
crates/matrix-sdk-indexeddb/src/event_cache_store Expand file tree Collapse file tree 3 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -748,6 +748,13 @@ macro_rules! event_cache_store_integration_tests {
748
748
get_event_cache_store( ) . await . unwrap( ) . into_event_cache_store( ) ;
749
749
event_cache_store. test_remove_room( ) . await ;
750
750
}
751
+
752
+ #[ async_test]
753
+ async fn test_filter_duplicated_events( ) {
754
+ let event_cache_store =
755
+ get_event_cache_store( ) . await . unwrap( ) . into_event_cache_store( ) ;
756
+ event_cache_store. test_filter_duplicated_events( ) . await ;
757
+ }
751
758
}
752
759
} ;
753
760
}
Original file line number Diff line number Diff line change @@ -435,10 +435,24 @@ impl_event_cache_store! {
435
435
events: Vec <OwnedEventId >,
436
436
) -> Result <Vec <( OwnedEventId , Position ) >, IndexeddbEventCacheStoreError > {
437
437
let _timer = timer!( "method" ) ;
438
- self . memory_store
439
- . filter_duplicated_events( linked_chunk_id, events)
440
- . await
441
- . map_err( IndexeddbEventCacheStoreError :: MemoryStore )
438
+
439
+ if events. is_empty( ) {
440
+ return Ok ( Vec :: new( ) ) ;
441
+ }
442
+
443
+ let linked_chunk_id = linked_chunk_id. to_owned( ) ;
444
+ let room_id = linked_chunk_id. room_id( ) ;
445
+ let transaction =
446
+ self . transaction( & [ keys:: EVENTS ] , IdbTransactionMode :: Readonly ) ?;
447
+ let mut duplicated = Vec :: new( ) ;
448
+ for event_id in events {
449
+ if let Some ( types:: Event :: InBand ( event) ) =
450
+ transaction. get_event_by_id( room_id, & event_id) . await ?
451
+ {
452
+ duplicated. push( ( event_id, event. position. into( ) ) ) ;
453
+ }
454
+ }
455
+ Ok ( duplicated)
442
456
}
443
457
444
458
#[ instrument( skip( self , event_id) ) ]
Original file line number Diff line number Diff line change @@ -570,6 +570,17 @@ impl<'a> IndexeddbEventCacheStoreTransaction<'a> {
570
570
self . delete_items_in_room :: < Chunk , IndexedChunkIdKey > ( room_id) . await
571
571
}
572
572
573
+ /// Query IndexedDB for events that match the given event id in the given
574
+ /// room. If more than one item is found, an error is returned.
575
+ pub async fn get_event_by_id (
576
+ & self ,
577
+ room_id : & RoomId ,
578
+ event_id : & OwnedEventId ,
579
+ ) -> Result < Option < Event > , IndexeddbEventCacheStoreTransactionError > {
580
+ let key = self . serializer . encode_key ( room_id, event_id) ;
581
+ self . get_item_by_key :: < Event , IndexedEventIdKey > ( room_id, key) . await
582
+ }
583
+
573
584
/// Query IndexedDB for events in the given position range in the given
574
585
/// room.
575
586
pub async fn get_events_by_position (
You can’t perform that action at this time.
0 commit comments