Skip to content

Commit 0ce163a

Browse files
committed
feat(sqlite): Add more timer! logs in each EventCacheStore methods.
This patch adds `timer!` logs in each method from `EventCacheStore` for `SqliteEventCacheStore`. It will help to know the execution duration of each of these methods.
1 parent 5b3f530 commit 0ce163a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ impl EventCacheStore for SqliteEventCacheStore {
465465
key: &str,
466466
holder: &str,
467467
) -> Result<bool> {
468+
let _timer = timer!("method");
469+
468470
let key = key.to_owned();
469471
let holder = holder.to_owned();
470472

@@ -498,6 +500,8 @@ impl EventCacheStore for SqliteEventCacheStore {
498500
linked_chunk_id: LinkedChunkId<'_>,
499501
updates: Vec<Update<Event, Gap>>,
500502
) -> Result<(), Self::Error> {
503+
let _timer = timer!("method");
504+
501505
// Use a single transaction throughout this function, so that either all updates
502506
// work, or none is taken into account.
503507
let hashed_linked_chunk_id =
@@ -826,6 +830,8 @@ impl EventCacheStore for SqliteEventCacheStore {
826830
&self,
827831
linked_chunk_id: LinkedChunkId<'_>,
828832
) -> Result<Vec<RawChunk<Event, Gap>>, Self::Error> {
833+
let _timer = timer!("method");
834+
829835
let hashed_linked_chunk_id =
830836
self.encode_key(keys::LINKED_CHUNKS, linked_chunk_id.storage_key());
831837

@@ -868,6 +874,8 @@ impl EventCacheStore for SqliteEventCacheStore {
868874
&self,
869875
linked_chunk_id: LinkedChunkId<'_>,
870876
) -> Result<Vec<ChunkMetadata>, Self::Error> {
877+
let _timer = timer!("method");
878+
871879
let hashed_linked_chunk_id =
872880
self.encode_key(keys::LINKED_CHUNKS, linked_chunk_id.storage_key());
873881

@@ -929,6 +937,8 @@ impl EventCacheStore for SqliteEventCacheStore {
929937
&self,
930938
linked_chunk_id: LinkedChunkId<'_>,
931939
) -> Result<(Option<RawChunk<Event, Gap>>, ChunkIdentifierGenerator), Self::Error> {
940+
let _timer = timer!("method");
941+
932942
let hashed_linked_chunk_id =
933943
self.encode_key(keys::LINKED_CHUNKS, linked_chunk_id.storage_key());
934944

@@ -1023,6 +1033,8 @@ impl EventCacheStore for SqliteEventCacheStore {
10231033
linked_chunk_id: LinkedChunkId<'_>,
10241034
before_chunk_identifier: ChunkIdentifier,
10251035
) -> Result<Option<RawChunk<Event, Gap>>, Self::Error> {
1036+
let _timer = timer!("method");
1037+
10261038
let hashed_linked_chunk_id =
10271039
self.encode_key(keys::LINKED_CHUNKS, linked_chunk_id.storage_key());
10281040

@@ -1071,6 +1083,8 @@ impl EventCacheStore for SqliteEventCacheStore {
10711083

10721084
#[instrument(skip(self))]
10731085
async fn clear_all_linked_chunks(&self) -> Result<(), Self::Error> {
1086+
let _timer = timer!("method");
1087+
10741088
self.write()
10751089
.await?
10761090
.with_transaction(move |txn| {
@@ -1080,6 +1094,7 @@ impl EventCacheStore for SqliteEventCacheStore {
10801094
txn.execute("DELETE FROM events", ())
10811095
})
10821096
.await?;
1097+
10831098
Ok(())
10841099
}
10851100

@@ -1089,6 +1104,8 @@ impl EventCacheStore for SqliteEventCacheStore {
10891104
linked_chunk_id: LinkedChunkId<'_>,
10901105
events: Vec<OwnedEventId>,
10911106
) -> Result<Vec<(OwnedEventId, Position)>, Self::Error> {
1107+
let _timer = timer!("method");
1108+
10921109
// If there's no events for which we want to check duplicates, we can return
10931110
// early. It's not only an optimization to do so: it's required, otherwise the
10941111
// `repeat_vars` call below will panic.
@@ -1169,6 +1186,8 @@ impl EventCacheStore for SqliteEventCacheStore {
11691186
room_id: &RoomId,
11701187
event_id: &EventId,
11711188
) -> Result<Option<Event>, Self::Error> {
1189+
let _timer = timer!("method");
1190+
11721191
let event_id = event_id.to_owned();
11731192
let this = self.clone();
11741193

@@ -1200,6 +1219,8 @@ impl EventCacheStore for SqliteEventCacheStore {
12001219
event_id: &EventId,
12011220
filters: Option<&[RelationType]>,
12021221
) -> Result<Vec<(Event, Option<Position>)>, Self::Error> {
1222+
let _timer = timer!("method");
1223+
12031224
let hashed_room_id = self.encode_key(keys::LINKED_CHUNKS, room_id);
12041225

12051226
let hashed_linked_chunk_id =
@@ -1264,6 +1285,8 @@ impl EventCacheStore for SqliteEventCacheStore {
12641285

12651286
#[instrument(skip(self, event))]
12661287
async fn save_event(&self, room_id: &RoomId, event: Event) -> Result<(), Self::Error> {
1288+
let _timer = timer!("method");
1289+
12671290
let Some(event_id) = event.event_id() else {
12681291
error!(%room_id, "Trying to save an event with no ID");
12691292
return Ok(());
@@ -1292,6 +1315,8 @@ impl EventCacheStore for SqliteEventCacheStore {
12921315
content: Vec<u8>,
12931316
ignore_policy: IgnoreMediaRetentionPolicy,
12941317
) -> Result<()> {
1318+
let _timer = timer!("method");
1319+
12951320
self.media_service.add_media_content(self, request, content, ignore_policy).await
12961321
}
12971322

@@ -1301,6 +1326,8 @@ impl EventCacheStore for SqliteEventCacheStore {
13011326
from: &MediaRequestParameters,
13021327
to: &MediaRequestParameters,
13031328
) -> Result<(), Self::Error> {
1329+
let _timer = timer!("method");
1330+
13041331
let prev_uri = self.encode_key(keys::MEDIA, from.source.unique_key());
13051332
let prev_format = self.encode_key(keys::MEDIA, from.format.unique_key());
13061333

@@ -1319,11 +1346,15 @@ impl EventCacheStore for SqliteEventCacheStore {
13191346

13201347
#[instrument(skip_all)]
13211348
async fn get_media_content(&self, request: &MediaRequestParameters) -> Result<Option<Vec<u8>>> {
1349+
let _timer = timer!("method");
1350+
13221351
self.media_service.get_media_content(self, request).await
13231352
}
13241353

13251354
#[instrument(skip_all)]
13261355
async fn remove_media_content(&self, request: &MediaRequestParameters) -> Result<()> {
1356+
let _timer = timer!("method");
1357+
13271358
let uri = self.encode_key(keys::MEDIA, request.source.unique_key());
13281359
let format = self.encode_key(keys::MEDIA, request.format.unique_key());
13291360

@@ -1338,11 +1369,15 @@ impl EventCacheStore for SqliteEventCacheStore {
13381369
&self,
13391370
uri: &MxcUri,
13401371
) -> Result<Option<Vec<u8>>, Self::Error> {
1372+
let _timer = timer!("method");
1373+
13411374
self.media_service.get_media_content_for_uri(self, uri).await
13421375
}
13431376

13441377
#[instrument(skip(self))]
13451378
async fn remove_media_content_for_uri(&self, uri: &MxcUri) -> Result<()> {
1379+
let _timer = timer!("method");
1380+
13461381
let uri = self.encode_key(keys::MEDIA, uri);
13471382

13481383
let conn = self.write().await?;
@@ -1356,11 +1391,15 @@ impl EventCacheStore for SqliteEventCacheStore {
13561391
&self,
13571392
policy: MediaRetentionPolicy,
13581393
) -> Result<(), Self::Error> {
1394+
let _timer = timer!("method");
1395+
13591396
self.media_service.set_media_retention_policy(self, policy).await
13601397
}
13611398

13621399
#[instrument(skip_all)]
13631400
fn media_retention_policy(&self) -> MediaRetentionPolicy {
1401+
let _timer = timer!("method");
1402+
13641403
self.media_service.media_retention_policy()
13651404
}
13661405

@@ -1370,11 +1409,15 @@ impl EventCacheStore for SqliteEventCacheStore {
13701409
request: &MediaRequestParameters,
13711410
ignore_policy: IgnoreMediaRetentionPolicy,
13721411
) -> Result<(), Self::Error> {
1412+
let _timer = timer!("method");
1413+
13731414
self.media_service.set_ignore_media_retention_policy(self, request, ignore_policy).await
13741415
}
13751416

13761417
#[instrument(skip_all)]
13771418
async fn clean_up_media_cache(&self) -> Result<(), Self::Error> {
1419+
let _timer = timer!("method");
1420+
13781421
self.media_service.clean_up_media_cache(self).await
13791422
}
13801423
}

0 commit comments

Comments
 (0)