Skip to content

Commit 1e11ac4

Browse files
committed
crypto: Use a BTreeMap for MemoryStores' OutboundGroupSessions
1 parent 486b6d6 commit 1e11ac4

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

crates/matrix-sdk-crypto/src/store/memorystore.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::{
16-
collections::{hash_map::Entry, HashMap, HashSet},
16+
collections::{hash_map::Entry, BTreeMap, HashMap, HashSet},
1717
convert::Infallible,
1818
sync::{Arc, RwLock as StdRwLock},
1919
time::{Duration, Instant},
@@ -54,7 +54,7 @@ pub struct MemoryStore {
5454
account: StdRwLock<Option<Account>>,
5555
sessions: SessionStore,
5656
inbound_group_sessions: GroupSessionStore,
57-
outbound_group_sessions: StdRwLock<Vec<OutboundGroupSession>>,
57+
outbound_group_sessions: StdRwLock<BTreeMap<OwnedRoomId, OutboundGroupSession>>,
5858
olm_hashes: StdRwLock<HashMap<String, HashSet<String>>>,
5959
devices: DeviceStore,
6060
identities: StdRwLock<HashMap<OwnedUserId, ReadOnlyUserIdentities>>,
@@ -122,8 +122,11 @@ impl MemoryStore {
122122
}
123123
}
124124

125-
fn save_outbound_group_sessions(&self, mut sessions: Vec<OutboundGroupSession>) {
126-
self.outbound_group_sessions.write().unwrap().append(&mut sessions);
125+
fn save_outbound_group_sessions(&self, sessions: Vec<OutboundGroupSession>) {
126+
self.outbound_group_sessions
127+
.write()
128+
.unwrap()
129+
.extend(sessions.into_iter().map(|s| (s.room_id().to_owned(), s)));
127130
}
128131
}
129132

@@ -308,13 +311,7 @@ impl CryptoStore for MemoryStore {
308311
&self,
309312
room_id: &RoomId,
310313
) -> Result<Option<OutboundGroupSession>> {
311-
Ok(self
312-
.outbound_group_sessions
313-
.read()
314-
.unwrap()
315-
.iter()
316-
.find(|session| session.room_id() == room_id)
317-
.cloned())
314+
Ok(self.outbound_group_sessions.read().unwrap().get(room_id).cloned())
318315
}
319316

320317
async fn load_tracked_users(&self) -> Result<Vec<TrackedUser>> {

0 commit comments

Comments
 (0)