Skip to content

Commit 05178cc

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): make room id a key component rather than fixed arg to IndexedKey::encode
Signed-off-by: Michael Goldenberg <[email protected]>
1 parent 65b9bd2 commit 05178cc

File tree

4 files changed

+223
-134
lines changed

4 files changed

+223
-134
lines changed

crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ impl IndexeddbEventCacheStoreSerializer {
7171
///
7272
/// Note that the particular key which is encoded is defined by the type
7373
/// `K`.
74-
pub fn encode_key<T, K>(&self, room_id: &RoomId, components: K::KeyComponents<'_>) -> K
74+
pub fn encode_key<T, K>(&self, _: &RoomId, components: K::KeyComponents<'_>) -> K
7575
where
7676
T: Indexed,
7777
K: IndexedKey<T>,
7878
{
79-
K::encode(room_id, components, &self.inner)
79+
K::encode(components, &self.inner)
8080
}
8181

8282
/// Encodes a key for a [`Indexed`] type as a [`JsValue`].
@@ -132,11 +132,11 @@ impl IndexeddbEventCacheStoreSerializer {
132132
{
133133
let range = match range.into() {
134134
IndexedKeyRange::Only(components) => {
135-
IndexedKeyRange::Only(K::encode(room_id, components, &self.inner))
135+
IndexedKeyRange::Only(K::encode(components, &self.inner))
136136
}
137137
IndexedKeyRange::Bound(lower, upper) => {
138-
let lower = K::encode(room_id, lower, &self.inner);
139-
let upper = K::encode(room_id, upper, &self.inner);
138+
let lower = K::encode(lower, &self.inner);
139+
let upper = K::encode(upper, &self.inner);
140140
IndexedKeyRange::Bound(lower, upper)
141141
}
142142
};

crates/matrix-sdk-indexeddb/src/event_cache_store/serializer/traits.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ pub trait IndexedKey<T: Indexed> {
6262
/// argument, which provides the necessary context for encryption and
6363
/// decryption, in the case that certain components of the key must be
6464
/// encrypted before storage.
65-
fn encode(
66-
room_id: &RoomId,
67-
components: Self::KeyComponents<'_>,
68-
serializer: &IndexeddbSerializer,
69-
) -> Self;
65+
fn encode(components: Self::KeyComponents<'_>, serializer: &IndexeddbSerializer) -> Self;
7066
}
7167

7268
/// A trait for constructing the bounds of an [`IndexedKey`].
@@ -103,12 +99,12 @@ where
10399
{
104100
/// Constructs the lower bound of the key.
105101
fn lower_key(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self {
106-
<Self as IndexedKey<T>>::encode(room_id, Self::lower_key_components(), serializer)
102+
<Self as IndexedKey<T>>::encode(Self::lower_key_components(), serializer)
107103
}
108104

109105
/// Constructs the upper bound of the key.
110106
fn upper_key(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self {
111-
<Self as IndexedKey<T>>::encode(room_id, Self::upper_key_components(), serializer)
107+
<Self as IndexedKey<T>>::encode(Self::upper_key_components(), serializer)
112108
}
113109
}
114110

@@ -153,6 +149,21 @@ pub trait IndexedPrefixKeyBounds<T: Indexed, P>: IndexedKey<T> {
153149
fn upper_key_with_prefix(prefix: P, serializer: &IndexeddbSerializer) -> Self;
154150
}
155151

152+
impl<'a, T, K, P> IndexedPrefixKeyBounds<T, P> for K
153+
where
154+
T: Indexed,
155+
K: IndexedPrefixKeyComponentBounds<'a, T, P> + Sized,
156+
P: 'a,
157+
{
158+
fn lower_key_with_prefix(prefix: P, serializer: &IndexeddbSerializer) -> Self {
159+
<Self as IndexedKey<T>>::encode(Self::lower_key_components_with_prefix(prefix), serializer)
160+
}
161+
162+
fn upper_key_with_prefix(prefix: P, serializer: &IndexeddbSerializer) -> Self {
163+
<Self as IndexedKey<T>>::encode(Self::upper_key_components_with_prefix(prefix), serializer)
164+
}
165+
}
166+
156167
/// A trait for constructing the bounds of the components of an [`IndexedKey`]
157168
/// given a prefix `P` of that key.
158169
///

0 commit comments

Comments
 (0)