|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | use std::{ |
16 | | - collections::{hash_map::Entry, HashMap, HashSet}, |
| 16 | + collections::{hash_map::Entry, BTreeMap, HashMap, HashSet}, |
17 | 17 | convert::Infallible, |
18 | 18 | sync::{Arc, RwLock as StdRwLock}, |
19 | 19 | time::{Duration, Instant}, |
@@ -54,7 +54,7 @@ pub struct MemoryStore { |
54 | 54 | account: StdRwLock<Option<Account>>, |
55 | 55 | sessions: SessionStore, |
56 | 56 | inbound_group_sessions: GroupSessionStore, |
57 | | - outbound_group_sessions: StdRwLock<Vec<OutboundGroupSession>>, |
| 57 | + outbound_group_sessions: StdRwLock<BTreeMap<OwnedRoomId, OutboundGroupSession>>, |
58 | 58 | olm_hashes: StdRwLock<HashMap<String, HashSet<String>>>, |
59 | 59 | devices: DeviceStore, |
60 | 60 | identities: StdRwLock<HashMap<OwnedUserId, ReadOnlyUserIdentities>>, |
@@ -122,8 +122,11 @@ impl MemoryStore { |
122 | 122 | } |
123 | 123 | } |
124 | 124 |
|
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))); |
127 | 130 | } |
128 | 131 | } |
129 | 132 |
|
@@ -308,13 +311,7 @@ impl CryptoStore for MemoryStore { |
308 | 311 | &self, |
309 | 312 | room_id: &RoomId, |
310 | 313 | ) -> 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()) |
318 | 315 | } |
319 | 316 |
|
320 | 317 | async fn load_tracked_users(&self) -> Result<Vec<TrackedUser>> { |
|
0 commit comments