From de5f00fd33baa67a5563192132c85a66741a0ace Mon Sep 17 00:00:00 2001 From: Michael Goldenberg Date: Tue, 5 Aug 2025 13:38:52 -0400 Subject: [PATCH] refactor(indexeddb): use references in IndexedEventRelationKey::KeyComponents Signed-off-by: Michael Goldenberg --- crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs | 4 ++-- .../src/event_cache_store/serializer/types.rs | 8 ++++---- .../src/event_cache_store/transaction.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs b/crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs index 33f40732a..12ff6816b 100644 --- a/crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs @@ -488,7 +488,7 @@ impl_event_cache_store! { match filters { Some(relation_types) if !relation_types.is_empty() => { for relation_type in relation_types { - let relation = (event_id.to_owned(), relation_type.clone()); + let relation = (event_id, relation_type); let events = transaction.get_events_by_relation(room_id, relation).await?; for event in events { let position = event.position().map(Into::into); @@ -498,7 +498,7 @@ impl_event_cache_store! { } _ => { for event in - transaction.get_events_by_related_event(room_id, event_id.to_owned()).await? + transaction.get_events_by_related_event(room_id, event_id).await? { let position = event.position().map(Into::into); related_events.push((event.into(), position)); diff --git a/crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/types.rs b/crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/types.rs index 1a999f74d..58c742c4a 100644 --- a/crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/types.rs +++ b/crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/types.rs @@ -340,7 +340,7 @@ impl Indexed for Event { let relation = self.relation().map(|(related_event, relation_type)| { IndexedEventRelationKey::encode( room_id, - (related_event, RelationType::from(relation_type)), + (&related_event, &RelationType::from(relation_type)), serializer, ) }); @@ -441,7 +441,7 @@ impl IndexedEventRelationKey { /// events which are related to the given event. pub fn with_related_event_id( &self, - related_event_id: &OwnedEventId, + related_event_id: &EventId, serializer: &IndexeddbSerializer, ) -> Self { let room_id = self.0.clone(); @@ -455,11 +455,11 @@ impl IndexedEventRelationKey { impl IndexedKey for IndexedEventRelationKey { const INDEX: Option<&'static str> = Some(keys::EVENTS_RELATION); - type KeyComponents<'a> = (OwnedEventId, RelationType); + type KeyComponents<'a> = (&'a EventId, &'a RelationType); fn encode( room_id: &RoomId, - (related_event_id, relation_type): (OwnedEventId, RelationType), + (related_event_id, relation_type): (&EventId, &RelationType), serializer: &IndexeddbSerializer, ) -> Self { let room_id = serializer.encode_key_as_string(keys::ROOMS, room_id); diff --git a/crates/matrix-sdk-indexeddb/src/event_cache_store/transaction.rs b/crates/matrix-sdk-indexeddb/src/event_cache_store/transaction.rs index d8d95d63e..92a7cc213 100644 --- a/crates/matrix-sdk-indexeddb/src/event_cache_store/transaction.rs +++ b/crates/matrix-sdk-indexeddb/src/event_cache_store/transaction.rs @@ -632,7 +632,7 @@ impl<'a> IndexeddbEventCacheStoreTransaction<'a> { pub async fn get_events_by_relation( &self, room_id: &RoomId, - range: impl Into>, + range: impl Into>, ) -> Result, IndexeddbEventCacheStoreTransactionError> { let range = range.into().encoded(room_id, self.serializer.inner()); self.get_items_by_key::(room_id, range).await @@ -643,12 +643,12 @@ impl<'a> IndexeddbEventCacheStoreTransaction<'a> { pub async fn get_events_by_related_event( &self, room_id: &RoomId, - related_event_id: OwnedEventId, + related_event_id: &EventId, ) -> Result, IndexeddbEventCacheStoreTransactionError> { let lower = IndexedEventRelationKey::lower_key(room_id, self.serializer.inner()) - .with_related_event_id(&related_event_id, self.serializer.inner()); + .with_related_event_id(related_event_id, self.serializer.inner()); let upper = IndexedEventRelationKey::upper_key(room_id, self.serializer.inner()) - .with_related_event_id(&related_event_id, self.serializer.inner()); + .with_related_event_id(related_event_id, self.serializer.inner()); let range = IndexedKeyRange::Bound(lower, upper); self.get_items_by_key::(room_id, range).await }