Skip to content

Commit 5a3ef30

Browse files
mgoldenbergHywan
authored andcommitted
refactor(indexeddb): remove redundant room id arg on relevant serializer and transaction fns
Signed-off-by: Michael Goldenberg <[email protected]>
1 parent 05178cc commit 5a3ef30

File tree

5 files changed

+68
-103
lines changed

5 files changed

+68
-103
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ impl_event_cache_store! {
160160
trace!(%room_id, "Inserting new chunk (prev={previous:?}, new={new:?}, next={next:?})");
161161
transaction
162162
.add_chunk(
163-
room_id,
164163
&types::Chunk {
165164
room_id: room_id.to_owned(),
166165
identifier: new.index(),
@@ -175,7 +174,6 @@ impl_event_cache_store! {
175174
trace!(%room_id, "Inserting new gap (prev={previous:?}, new={new:?}, next={next:?})");
176175
transaction
177176
.add_item(
178-
room_id,
179177
&types::Gap {
180178
room_id: room_id.to_owned(),
181179
chunk_identifier: new.index(),
@@ -185,7 +183,6 @@ impl_event_cache_store! {
185183
.await?;
186184
transaction
187185
.add_chunk(
188-
room_id,
189186
&types::Chunk {
190187
room_id: room_id.to_owned(),
191188
identifier: new.index(),
@@ -207,8 +204,7 @@ impl_event_cache_store! {
207204

208205
for (i, item) in items.into_iter().enumerate() {
209206
transaction
210-
.put_item(
211-
room_id,
207+
.put_event(
212208
&types::Event::InBand(InBandEvent {
213209
room_id: room_id.to_owned(),
214210
content: item,
@@ -229,7 +225,6 @@ impl_event_cache_store! {
229225

230226
transaction
231227
.put_event(
232-
room_id,
233228
&types::Event::InBand(InBandEvent {
234229
room_id: room_id.to_owned(),
235230
content: item,
@@ -531,7 +526,7 @@ impl_event_cache_store! {
531526
Some(mut inner) => inner.with_content(event),
532527
None => types::Event::OutOfBand(OutOfBandEvent { room_id: room_id.to_owned(), content: event, position: () }),
533528
};
534-
transaction.put_event(room_id, &event).await?;
529+
transaction.put_event(&event).await?;
535530
transaction.commit().await?;
536531
Ok(())
537532
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ 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, _: &RoomId, components: K::KeyComponents<'_>) -> K
74+
pub fn encode_key<T, K>(&self, components: K::KeyComponents<'_>) -> K
7575
where
7676
T: Indexed,
7777
K: IndexedKey<T>,
@@ -85,14 +85,13 @@ impl IndexeddbEventCacheStoreSerializer {
8585
/// `K`.
8686
pub fn encode_key_as_value<T, K>(
8787
&self,
88-
room_id: &RoomId,
8988
components: K::KeyComponents<'_>,
9089
) -> Result<JsValue, serde_wasm_bindgen::Error>
9190
where
9291
T: Indexed,
9392
K: IndexedKey<T> + Serialize,
9493
{
95-
serde_wasm_bindgen::to_value(&self.encode_key::<T, K>(room_id, components))
94+
serde_wasm_bindgen::to_value(&self.encode_key::<T, K>(components))
9695
}
9796

9897
/// Encodes a key component range for an [`Indexed`] type.
@@ -101,7 +100,6 @@ impl IndexeddbEventCacheStoreSerializer {
101100
/// `K`.
102101
pub fn encode_key_range<T, K>(
103102
&self,
104-
room_id: &RoomId,
105103
range: impl Into<IndexedKeyRange<K>>,
106104
) -> Result<IdbKeyRange, serde_wasm_bindgen::Error>
107105
where
@@ -123,7 +121,6 @@ impl IndexeddbEventCacheStoreSerializer {
123121
/// `K`.
124122
pub fn encode_key_component_range<'a, T, K>(
125123
&self,
126-
room_id: &RoomId,
127124
range: impl Into<IndexedKeyRange<K::KeyComponents<'a>>>,
128125
) -> Result<IdbKeyRange, serde_wasm_bindgen::Error>
129126
where
@@ -140,13 +137,12 @@ impl IndexeddbEventCacheStoreSerializer {
140137
IndexedKeyRange::Bound(lower, upper)
141138
}
142139
};
143-
self.encode_key_range::<T, K>(room_id, range)
140+
self.encode_key_range::<T, K>(range)
144141
}
145142

146143
/// Serializes an [`Indexed`] type into a [`JsValue`]
147144
pub fn serialize<T>(
148145
&self,
149-
room_id: &RoomId,
150146
t: &T,
151147
) -> Result<JsValue, IndexeddbEventCacheStoreSerializerError<T::Error>>
152148
where

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ pub trait IndexedKey<T: Indexed> {
8686
/// the proper bound.
8787
pub trait IndexedKeyBounds<T: Indexed>: IndexedKey<T> {
8888
/// Constructs the lower bound of the key.
89-
fn lower_key(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self;
89+
fn lower_key(serializer: &IndexeddbSerializer) -> Self;
9090

9191
/// Constructs the upper bound of the key.
92-
fn upper_key(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self;
92+
fn upper_key(serializer: &IndexeddbSerializer) -> Self;
9393
}
9494

9595
impl<T, K> IndexedKeyBounds<T> for K
@@ -98,12 +98,12 @@ where
9898
K: IndexedKeyComponentBounds<T> + Sized,
9999
{
100100
/// Constructs the lower bound of the key.
101-
fn lower_key(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self {
101+
fn lower_key(serializer: &IndexeddbSerializer) -> Self {
102102
<Self as IndexedKey<T>>::encode(Self::lower_key_components(), serializer)
103103
}
104104

105105
/// Constructs the upper bound of the key.
106-
fn upper_key(room_id: &RoomId, serializer: &IndexeddbSerializer) -> Self {
106+
fn upper_key(serializer: &IndexeddbSerializer) -> Self {
107107
<Self as IndexedKey<T>>::encode(Self::upper_key_components(), serializer)
108108
}
109109
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,7 @@ pub enum IndexedKeyRange<K> {
165165
impl<'a, C: 'a> IndexedKeyRange<C> {
166166
/// Encodes a range of key components of type `K::KeyComponents`
167167
/// into a range of keys of type `K`.
168-
pub fn encoded<T, K>(
169-
self,
170-
room_id: &RoomId,
171-
serializer: &IndexeddbSerializer,
172-
) -> IndexedKeyRange<K>
168+
pub fn encoded<T, K>(self, serializer: &IndexeddbSerializer) -> IndexedKeyRange<K>
173169
where
174170
T: Indexed,
175171
K: IndexedKey<T, KeyComponents<'a> = C>,
@@ -194,12 +190,12 @@ impl<K> IndexedKeyRange<K> {
194190
}
195191
}
196192

197-
pub fn all<T>(room_id: &RoomId, serializer: &IndexeddbSerializer) -> IndexedKeyRange<K>
193+
pub fn all<T>(serializer: &IndexeddbSerializer) -> IndexedKeyRange<K>
198194
where
199195
T: Indexed,
200196
K: IndexedKeyBounds<T>,
201197
{
202-
IndexedKeyRange::Bound(K::lower_key(room_id, serializer), K::upper_key(room_id, serializer))
198+
IndexedKeyRange::Bound(K::lower_key(serializer), K::upper_key(serializer))
203199
}
204200

205201
pub fn all_with_prefix<T, P>(prefix: P, serializer: &IndexeddbSerializer) -> IndexedKeyRange<K>

0 commit comments

Comments
 (0)