Skip to content

Commit d73a02c

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 f73199b commit d73a02c

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 =
@@ -1226,6 +1247,8 @@ impl EventCacheStore for SqliteEventCacheStore {
12261247

12271248
#[instrument(skip(self, event))]
12281249
async fn save_event(&self, room_id: &RoomId, event: Event) -> Result<(), Self::Error> {
1250+
let _timer = timer!("method");
1251+
12291252
let Some(event_id) = event.event_id() else {
12301253
error!(%room_id, "Trying to save an event with no ID");
12311254
return Ok(());
@@ -1254,6 +1277,8 @@ impl EventCacheStore for SqliteEventCacheStore {
12541277
content: Vec<u8>,
12551278
ignore_policy: IgnoreMediaRetentionPolicy,
12561279
) -> Result<()> {
1280+
let _timer = timer!("method");
1281+
12571282
self.media_service.add_media_content(self, request, content, ignore_policy).await
12581283
}
12591284

@@ -1263,6 +1288,8 @@ impl EventCacheStore for SqliteEventCacheStore {
12631288
from: &MediaRequestParameters,
12641289
to: &MediaRequestParameters,
12651290
) -> Result<(), Self::Error> {
1291+
let _timer = timer!("method");
1292+
12661293
let prev_uri = self.encode_key(keys::MEDIA, from.source.unique_key());
12671294
let prev_format = self.encode_key(keys::MEDIA, from.format.unique_key());
12681295

@@ -1281,11 +1308,15 @@ impl EventCacheStore for SqliteEventCacheStore {
12811308

12821309
#[instrument(skip_all)]
12831310
async fn get_media_content(&self, request: &MediaRequestParameters) -> Result<Option<Vec<u8>>> {
1311+
let _timer = timer!("method");
1312+
12841313
self.media_service.get_media_content(self, request).await
12851314
}
12861315

12871316
#[instrument(skip_all)]
12881317
async fn remove_media_content(&self, request: &MediaRequestParameters) -> Result<()> {
1318+
let _timer = timer!("method");
1319+
12891320
let uri = self.encode_key(keys::MEDIA, request.source.unique_key());
12901321
let format = self.encode_key(keys::MEDIA, request.format.unique_key());
12911322

@@ -1300,11 +1331,15 @@ impl EventCacheStore for SqliteEventCacheStore {
13001331
&self,
13011332
uri: &MxcUri,
13021333
) -> Result<Option<Vec<u8>>, Self::Error> {
1334+
let _timer = timer!("method");
1335+
13031336
self.media_service.get_media_content_for_uri(self, uri).await
13041337
}
13051338

13061339
#[instrument(skip(self))]
13071340
async fn remove_media_content_for_uri(&self, uri: &MxcUri) -> Result<()> {
1341+
let _timer = timer!("method");
1342+
13081343
let uri = self.encode_key(keys::MEDIA, uri);
13091344

13101345
let conn = self.write().await?;
@@ -1318,11 +1353,15 @@ impl EventCacheStore for SqliteEventCacheStore {
13181353
&self,
13191354
policy: MediaRetentionPolicy,
13201355
) -> Result<(), Self::Error> {
1356+
let _timer = timer!("method");
1357+
13211358
self.media_service.set_media_retention_policy(self, policy).await
13221359
}
13231360

13241361
#[instrument(skip_all)]
13251362
fn media_retention_policy(&self) -> MediaRetentionPolicy {
1363+
let _timer = timer!("method");
1364+
13261365
self.media_service.media_retention_policy()
13271366
}
13281367

@@ -1332,11 +1371,15 @@ impl EventCacheStore for SqliteEventCacheStore {
13321371
request: &MediaRequestParameters,
13331372
ignore_policy: IgnoreMediaRetentionPolicy,
13341373
) -> Result<(), Self::Error> {
1374+
let _timer = timer!("method");
1375+
13351376
self.media_service.set_ignore_media_retention_policy(self, request, ignore_policy).await
13361377
}
13371378

13381379
#[instrument(skip_all)]
13391380
async fn clean_up_media_cache(&self) -> Result<(), Self::Error> {
1381+
let _timer = timer!("method");
1382+
13401383
self.media_service.clean_up_media_cache(self).await
13411384
}
13421385
}

0 commit comments

Comments
 (0)