refactor(indexeddb): use references in IndexedEventRelationKey::KeyComponents

Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
Michael Goldenberg
2025-08-05 13:38:52 -04:00
committed by Ivan Enderlin
parent 33c16b2979
commit de5f00fd33
3 changed files with 10 additions and 10 deletions

View File

@@ -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));

View File

@@ -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<Event> 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);

View File

@@ -632,7 +632,7 @@ impl<'a> IndexeddbEventCacheStoreTransaction<'a> {
pub async fn get_events_by_relation(
&self,
room_id: &RoomId,
range: impl Into<IndexedKeyRange<(OwnedEventId, RelationType)>>,
range: impl Into<IndexedKeyRange<(&EventId, &RelationType)>>,
) -> Result<Vec<Event>, IndexeddbEventCacheStoreTransactionError> {
let range = range.into().encoded(room_id, self.serializer.inner());
self.get_items_by_key::<Event, IndexedEventRelationKey>(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<Vec<Event>, 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::<Event, IndexedEventRelationKey>(room_id, range).await
}