@@ -28,9 +28,10 @@ use matrix_sdk_base::{
28
28
RawChunk , Update ,
29
29
} ,
30
30
media:: MediaRequestParameters ,
31
+ timer,
31
32
} ;
32
33
use ruma:: { events:: relation:: RelationType , EventId , MxcUri , OwnedEventId , RoomId } ;
33
- use tracing:: trace;
34
+ use tracing:: { instrument , trace} ;
34
35
use web_sys:: IdbTransactionMode ;
35
36
36
37
use crate :: event_cache_store:: {
@@ -123,23 +124,28 @@ macro_rules! impl_event_cache_store {
123
124
}
124
125
125
126
impl_event_cache_store ! {
127
+ #[ instrument( skip( self ) ) ]
126
128
async fn try_take_leased_lock(
127
129
& self ,
128
130
lease_duration_ms: u32 ,
129
131
key: & str ,
130
132
holder: & str ,
131
133
) -> Result <bool , IndexeddbEventCacheStoreError > {
134
+ let _timer = timer!( "method" ) ;
132
135
self . memory_store
133
136
. try_take_leased_lock( lease_duration_ms, key, holder)
134
137
. await
135
138
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
136
139
}
137
140
141
+ #[ instrument( skip( self , updates) ) ]
138
142
async fn handle_linked_chunk_updates(
139
143
& self ,
140
144
linked_chunk_id: LinkedChunkId <' _>,
141
145
updates: Vec <Update <Event , Gap >>,
142
146
) -> Result <( ) , IndexeddbEventCacheStoreError > {
147
+ let _timer = timer!( "method" ) ;
148
+
143
149
let linked_chunk_id = linked_chunk_id. to_owned( ) ;
144
150
let room_id = linked_chunk_id. room_id( ) ;
145
151
@@ -258,10 +264,13 @@ impl_event_cache_store! {
258
264
Ok ( ( ) )
259
265
}
260
266
267
+ #[ instrument( skip( self ) ) ]
261
268
async fn load_all_chunks(
262
269
& self ,
263
270
linked_chunk_id: LinkedChunkId <' _>,
264
271
) -> Result <Vec <RawChunk <Event , Gap >>, IndexeddbEventCacheStoreError > {
272
+ let _ = timer!( "method" ) ;
273
+
265
274
let linked_chunk_id = linked_chunk_id. to_owned( ) ;
266
275
let room_id = linked_chunk_id. room_id( ) ;
267
276
@@ -283,10 +292,23 @@ impl_event_cache_store! {
283
292
Ok ( raw_chunks)
284
293
}
285
294
295
+ #[ instrument( skip( self ) ) ]
286
296
async fn load_all_chunks_metadata(
287
297
& self ,
288
298
linked_chunk_id: LinkedChunkId <' _>,
289
299
) -> Result <Vec <ChunkMetadata >, IndexeddbEventCacheStoreError > {
300
+ // TODO: This call could possibly take a very long time and the
301
+ // amount of time increases linearly with the number of chunks
302
+ // it needs to load from the database. This will likely require
303
+ // some refactoring to deal with performance issues.
304
+ //
305
+ // For details on the performance penalties associated with this
306
+ // call, see https://github.com/matrix-org/matrix-rust-sdk/pull/5407.
307
+ //
308
+ // For how this was improved in the SQLite implementation, see
309
+ // https://github.com/matrix-org/matrix-rust-sdk/pull/5382.
310
+ let _ = timer!( "method" ) ;
311
+
290
312
let linked_chunk_id = linked_chunk_id. to_owned( ) ;
291
313
let room_id = linked_chunk_id. room_id( ) ;
292
314
@@ -310,13 +332,16 @@ impl_event_cache_store! {
310
332
Ok ( raw_chunks)
311
333
}
312
334
335
+ #[ instrument( skip( self ) ) ]
313
336
async fn load_last_chunk(
314
337
& self ,
315
338
linked_chunk_id: LinkedChunkId <' _>,
316
339
) -> Result <
317
340
( Option <RawChunk <Event , Gap >>, ChunkIdentifierGenerator ) ,
318
341
IndexeddbEventCacheStoreError ,
319
342
> {
343
+ let _timer = timer!( "method" ) ;
344
+
320
345
let linked_chunk_id = linked_chunk_id. to_owned( ) ;
321
346
let room_id = linked_chunk_id. room_id( ) ;
322
347
let transaction = self . transaction(
@@ -365,11 +390,14 @@ impl_event_cache_store! {
365
390
}
366
391
}
367
392
393
+ #[ instrument( skip( self ) ) ]
368
394
async fn load_previous_chunk(
369
395
& self ,
370
396
linked_chunk_id: LinkedChunkId <' _>,
371
397
before_chunk_identifier: ChunkIdentifier ,
372
398
) -> Result <Option <RawChunk <Event , Gap >>, IndexeddbEventCacheStoreError > {
399
+ let _timer = timer!( "method" ) ;
400
+
373
401
let linked_chunk_id = linked_chunk_id. to_owned( ) ;
374
402
let room_id = linked_chunk_id. room_id( ) ;
375
403
let transaction = self . transaction(
@@ -385,7 +413,10 @@ impl_event_cache_store! {
385
413
Ok ( None )
386
414
}
387
415
416
+ #[ instrument( skip( self ) ) ]
388
417
async fn clear_all_linked_chunks( & self ) -> Result <( ) , IndexeddbEventCacheStoreError > {
418
+ let _timer = timer!( "method" ) ;
419
+
389
420
let transaction = self . transaction(
390
421
& [ keys:: LINKED_CHUNKS , keys:: EVENTS , keys:: GAPS ] ,
391
422
IdbTransactionMode :: Readwrite ,
@@ -397,140 +428,168 @@ impl_event_cache_store! {
397
428
Ok ( ( ) )
398
429
}
399
430
431
+ #[ instrument( skip( self , events) ) ]
400
432
async fn filter_duplicated_events(
401
433
& self ,
402
434
linked_chunk_id: LinkedChunkId <' _>,
403
435
events: Vec <OwnedEventId >,
404
436
) -> Result <Vec <( OwnedEventId , Position ) >, IndexeddbEventCacheStoreError > {
437
+ let _timer = timer!( "method" ) ;
405
438
self . memory_store
406
439
. filter_duplicated_events( linked_chunk_id, events)
407
440
. await
408
441
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
409
442
}
410
443
444
+ #[ instrument( skip( self , event_id) ) ]
411
445
async fn find_event(
412
446
& self ,
413
447
room_id: & RoomId ,
414
448
event_id: & EventId ,
415
449
) -> Result <Option <Event >, IndexeddbEventCacheStoreError > {
450
+ let _timer = timer!( "method" ) ;
416
451
self . memory_store
417
452
. find_event( room_id, event_id)
418
453
. await
419
454
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
420
455
}
421
456
457
+ #[ instrument( skip( self , event_id, filters) ) ]
422
458
async fn find_event_relations(
423
459
& self ,
424
460
room_id: & RoomId ,
425
461
event_id: & EventId ,
426
462
filters: Option <& [ RelationType ] >,
427
463
) -> Result <Vec <( Event , Option <Position >) >, IndexeddbEventCacheStoreError > {
464
+ let _timer = timer!( "method" ) ;
428
465
self . memory_store
429
466
. find_event_relations( room_id, event_id, filters)
430
467
. await
431
468
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
432
469
}
433
470
471
+ #[ instrument( skip( self , event) ) ]
434
472
async fn save_event(
435
473
& self ,
436
474
room_id: & RoomId ,
437
475
event: Event ,
438
476
) -> Result <( ) , IndexeddbEventCacheStoreError > {
477
+ let _timer = timer!( "method" ) ;
439
478
self . memory_store
440
479
. save_event( room_id, event)
441
480
. await
442
481
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
443
482
}
444
483
484
+ #[ instrument( skip_all) ]
445
485
async fn add_media_content(
446
486
& self ,
447
487
request: & MediaRequestParameters ,
448
488
content: Vec <u8 >,
449
489
ignore_policy: IgnoreMediaRetentionPolicy ,
450
490
) -> Result <( ) , IndexeddbEventCacheStoreError > {
491
+ let _timer = timer!( "method" ) ;
451
492
self . memory_store
452
493
. add_media_content( request, content, ignore_policy)
453
494
. await
454
495
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
455
496
}
456
497
498
+ #[ instrument( skip_all) ]
457
499
async fn replace_media_key(
458
500
& self ,
459
501
from: & MediaRequestParameters ,
460
502
to: & MediaRequestParameters ,
461
503
) -> Result <( ) , IndexeddbEventCacheStoreError > {
504
+ let _timer = timer!( "method" ) ;
462
505
self . memory_store
463
506
. replace_media_key( from, to)
464
507
. await
465
508
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
466
509
}
467
510
511
+ #[ instrument( skip_all) ]
468
512
async fn get_media_content(
469
513
& self ,
470
514
request: & MediaRequestParameters ,
471
515
) -> Result <Option <Vec <u8 >>, IndexeddbEventCacheStoreError > {
516
+ let _timer = timer!( "method" ) ;
472
517
self . memory_store
473
518
. get_media_content( request)
474
519
. await
475
520
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
476
521
}
477
522
523
+ #[ instrument( skip_all) ]
478
524
async fn remove_media_content(
479
525
& self ,
480
526
request: & MediaRequestParameters ,
481
527
) -> Result <( ) , IndexeddbEventCacheStoreError > {
528
+ let _timer = timer!( "method" ) ;
482
529
self . memory_store
483
530
. remove_media_content( request)
484
531
. await
485
532
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
486
533
}
487
534
535
+ #[ instrument( skip( self ) ) ]
488
536
async fn get_media_content_for_uri(
489
537
& self ,
490
538
uri: & MxcUri ,
491
539
) -> Result <Option <Vec <u8 >>, IndexeddbEventCacheStoreError > {
540
+ let _timer = timer!( "method" ) ;
492
541
self . memory_store
493
542
. get_media_content_for_uri( uri)
494
543
. await
495
544
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
496
545
}
497
546
547
+ #[ instrument( skip( self ) ) ]
498
548
async fn remove_media_content_for_uri(
499
549
& self ,
500
550
uri: & MxcUri ,
501
551
) -> Result <( ) , IndexeddbEventCacheStoreError > {
552
+ let _timer = timer!( "method" ) ;
502
553
self . memory_store
503
554
. remove_media_content_for_uri( uri)
504
555
. await
505
556
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
506
557
}
507
558
559
+ #[ instrument( skip_all) ]
508
560
async fn set_media_retention_policy(
509
561
& self ,
510
562
policy: MediaRetentionPolicy ,
511
563
) -> Result <( ) , IndexeddbEventCacheStoreError > {
564
+ let _timer = timer!( "method" ) ;
512
565
self . memory_store
513
566
. set_media_retention_policy( policy)
514
567
. await
515
568
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
516
569
}
517
570
571
+ #[ instrument( skip_all) ]
518
572
fn media_retention_policy( & self ) -> MediaRetentionPolicy {
573
+ let _timer = timer!( "method" ) ;
519
574
self . memory_store. media_retention_policy( )
520
575
}
521
576
577
+ #[ instrument( skip_all) ]
522
578
async fn set_ignore_media_retention_policy(
523
579
& self ,
524
580
request: & MediaRequestParameters ,
525
581
ignore_policy: IgnoreMediaRetentionPolicy ,
526
582
) -> Result <( ) , IndexeddbEventCacheStoreError > {
583
+ let _timer = timer!( "method" ) ;
527
584
self . memory_store
528
585
. set_ignore_media_retention_policy( request, ignore_policy)
529
586
. await
530
587
. map_err( IndexeddbEventCacheStoreError :: MemoryStore )
531
588
}
532
589
590
+ #[ instrument( skip_all) ]
533
591
async fn clean_up_media_cache( & self ) -> Result <( ) , IndexeddbEventCacheStoreError > {
592
+ let _timer = timer!( "method" ) ;
534
593
self . memory_store
535
594
. clean_up_media_cache( )
536
595
. await
0 commit comments