Skip to content

Commit

Permalink
cont!
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Nov 20, 2024
1 parent 74b346f commit f99cb26
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 150 deletions.
14 changes: 8 additions & 6 deletions crates/matrix-sdk-base/src/event_cache/store/memory_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ use std::{collections::HashMap, num::NonZeroUsize, sync::RwLock as StdRwLock, ti

use async_trait::async_trait;
use matrix_sdk_common::{
linked_chunk::{LinkedChunk, Update},
linked_chunk::Update,
ring_buffer::RingBuffer,
store_locks::memory_store_helper::{handle_linked_chunk_updates, try_take_leased_lock},
store_locks::memory_store_helper::{
relational_linked_chunk::RelationalLinkedChunk, try_take_leased_lock,
},
};
use ruma::{MxcUri, OwnedMxcUri};

use super::{EventCacheStore, EventCacheStoreError, Result};
use crate::{
event_cache::{Event, Gap, DEFAULT_CHUNK_CAPACITY},
event_cache::{Event, Gap},
media::{MediaRequestParameters, UniqueKey as _},
};

Expand All @@ -36,7 +38,7 @@ use crate::{
pub struct MemoryStore {
media: StdRwLock<RingBuffer<(OwnedMxcUri, String /* unique key */, Vec<u8>)>>,
leases: StdRwLock<HashMap<String, (String, Instant)>>,
events: StdRwLock<LinkedChunk<DEFAULT_CHUNK_CAPACITY, Event, Gap>>,
events: StdRwLock<RelationalLinkedChunk<Event, Gap>>,
}

// SAFETY: `new_unchecked` is safe because 20 is not zero.
Expand All @@ -47,7 +49,7 @@ impl Default for MemoryStore {
Self {
media: StdRwLock::new(RingBuffer::new(NUMBER_OF_MEDIAS)),
leases: Default::default(),
events: StdRwLock::new(LinkedChunk::new()),
events: StdRwLock::new(RelationalLinkedChunk::new()),
}
}
}
Expand Down Expand Up @@ -77,7 +79,7 @@ impl EventCacheStore for MemoryStore {
&self,
updates: &[Update<Event, Gap>],
) -> Result<(), Self::Error> {
Ok(handle_linked_chunk_updates(&self.events, updates))
Ok(self.events.write().unwrap().apply_updates(updates))
}

async fn add_media_content(
Expand Down
Loading

0 comments on commit f99cb26

Please sign in to comment.