Skip to content

Commit

Permalink
!fixup rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Mar 11, 2024
1 parent 9b815dd commit 1d2dc08
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
3 changes: 0 additions & 3 deletions crates/matrix-sdk/src/event_cache/linked_chunk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// TODO: remove this once finished
#![allow(dead_code)]

use std::{fmt, ops::Not, ptr::NonNull};

#[derive(Debug)]
Expand Down
3 changes: 0 additions & 3 deletions crates/matrix-sdk/src/event_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,6 @@ impl RoomEventCache {
) -> Result<(Vec<SyncTimelineEvent>, Receiver<RoomEventCacheUpdate>)> {
let store = self.inner.store.lock().await;

// TODO: replace `room_events` by `room_events2` once it's ready.
let _dummy_temp_value = self.inner.store.room_events2(self.inner.room.room_id()).await;

Ok((store.room_events(self.inner.room.room_id()).await?, self.inner.sender.subscribe()))
}
}
Expand Down
25 changes: 6 additions & 19 deletions crates/matrix-sdk/src/event_cache/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{
collections::BTreeMap, fmt, iter::once, ops::Deref, result::Result as StdResult, sync::Arc,
};
use std::{collections::BTreeMap, fmt, iter::once, result::Result as StdResult, sync::Arc};

use async_trait::async_trait;
use matrix_sdk_base::deserialized_responses::SyncTimelineEvent;
use ruma::{OwnedRoomId, RoomId};
use tokio::sync::{OwnedRwLockReadGuard, RwLock};
use tokio::sync::RwLock;

use super::{
linked_chunk::{
Chunk, ChunkPosition, ItemPosition, LinkedChunk, LinkedChunkError, LinkedChunkIter,
LinkedChunkIterBackward,
},
EventCacheError, Result,
Result,
};

/// A store that can be remember information about the event cache.
Expand All @@ -39,8 +37,6 @@ pub trait EventCacheStore: Send + Sync {
/// Returns all the known events for the given room.
async fn room_events(&self, room: &RoomId) -> Result<Vec<SyncTimelineEvent>>;

async fn room_events2(&self, room: &RoomId) -> Result<Box<dyn Deref<Target = RoomEvents>>>;

/// Adds all the events to the given room.
async fn add_room_events(&self, room: &RoomId, events: Vec<SyncTimelineEvent>) -> Result<()>;

Expand Down Expand Up @@ -69,19 +65,9 @@ impl EventCacheStore for MemoryStore {
Ok(self.by_room.read().await.get(room).cloned().unwrap_or_default())
}

async fn room_events2(&self, room_id: &RoomId) -> Result<Box<dyn Deref<Target = RoomEvents>>> {
let boxed_guard: Box<dyn Deref<Target = RoomEvents>> =
OwnedRwLockReadGuard::try_map(self.by_room2.clone().read_owned().await, |btree| {
btree.get(room_id)
})
.map_err(|_| EventCacheError::RoomNotFound(room_id.to_owned()))
.map(Box::new)?;

Ok(boxed_guard)
}

async fn add_room_events(&self, room: &RoomId, events: Vec<SyncTimelineEvent>) -> Result<()> {
self.by_room.write().await.entry(room.to_owned()).or_default().extend(events);
self.by_room.write().await.entry(room.to_owned()).or_default().extend(events.clone());
self.by_room2.write().await.entry(room.to_owned()).or_default().push_events(events);
Ok(())
}

Expand All @@ -103,6 +89,7 @@ impl Default for RoomEvents {
}
}

#[allow(dead_code)]
impl RoomEvents {
pub fn new() -> Self {
Self { chunks: LinkedChunk::new() }
Expand Down

0 comments on commit 1d2dc08

Please sign in to comment.