mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 21:52:30 -04:00
refactor(sdk): Remove media caching from in-memory state store
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -2529,15 +2529,6 @@ dependencies = [
|
||||
"thread-id",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6e8aaa3f231bb4bd57b84b2d5dc3ae7f350265df8aa96492e0bc394a1571909"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maplit"
|
||||
version = "1.0.2"
|
||||
@@ -2659,7 +2650,6 @@ dependencies = [
|
||||
"futures-signals",
|
||||
"futures-util",
|
||||
"http",
|
||||
"lru",
|
||||
"matrix-sdk-common",
|
||||
"matrix-sdk-crypto",
|
||||
"matrix-sdk-store-encryption",
|
||||
|
||||
@@ -34,7 +34,6 @@ futures-core = "0.3.21"
|
||||
futures-signals = { version = "0.3.30", default-features = false }
|
||||
futures-util = { version = "0.3.21", default-features = false }
|
||||
http = { version = "0.2.6", optional = true }
|
||||
lru = "0.8.0"
|
||||
matrix-sdk-common = { version = "0.6.0", path = "../matrix-sdk-common" }
|
||||
matrix-sdk-crypto = { version = "0.6.0", path = "../matrix-sdk-crypto", optional = true }
|
||||
matrix-sdk-store-encryption = { version = "0.2.0", path = "../matrix-sdk-store-encryption" }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,6 @@ use std::{
|
||||
|
||||
use async_trait::async_trait;
|
||||
use dashmap::{DashMap, DashSet};
|
||||
use lru::LruCache;
|
||||
#[allow(unused_imports)]
|
||||
use matrix_sdk_common::{instant::Instant, locks::Mutex};
|
||||
use ruma::{
|
||||
@@ -38,11 +37,7 @@ use ruma::{
|
||||
use tracing::{info, warn};
|
||||
|
||||
use super::{Result, RoomInfo, StateChanges, StateStore, StoreError};
|
||||
use crate::{
|
||||
deserialized_responses::MemberEvent,
|
||||
media::{MediaRequest, UniqueKey},
|
||||
MinimalRoomMemberEvent,
|
||||
};
|
||||
use crate::{deserialized_responses::MemberEvent, media::MediaRequest, MinimalRoomMemberEvent};
|
||||
|
||||
/// In-Memory, non-persistent implementation of the `StateStore`
|
||||
///
|
||||
@@ -76,7 +71,6 @@ pub struct MemoryStore {
|
||||
room_event_receipts: Arc<
|
||||
DashMap<OwnedRoomId, DashMap<String, DashMap<OwnedEventId, DashMap<OwnedUserId, Receipt>>>>,
|
||||
>,
|
||||
media: Arc<Mutex<LruCache<String, Vec<u8>>>>,
|
||||
custom: Arc<DashMap<Vec<u8>, Vec<u8>>>,
|
||||
}
|
||||
|
||||
@@ -110,6 +104,7 @@ impl MemoryStore {
|
||||
presence: Default::default(),
|
||||
room_user_receipts: Default::default(),
|
||||
room_event_receipts: Default::default(),
|
||||
#[cfg(feature = "memory-media-cache")]
|
||||
media: Arc::new(Mutex::new(LruCache::new(
|
||||
100.try_into().expect("100 is a non-zero usize"),
|
||||
))),
|
||||
@@ -526,36 +521,17 @@ impl MemoryStore {
|
||||
Ok(self.custom.insert(key.to_vec(), value))
|
||||
}
|
||||
|
||||
async fn add_media_content(&self, request: &MediaRequest, data: Vec<u8>) -> Result<()> {
|
||||
self.media.lock().await.put(request.unique_key(), data);
|
||||
|
||||
// The in-memory store doesn't cache media
|
||||
async fn add_media_content(&self, _request: &MediaRequest, _data: Vec<u8>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_media_content(&self, request: &MediaRequest) -> Result<Option<Vec<u8>>> {
|
||||
Ok(self.media.lock().await.get(&request.unique_key()).cloned())
|
||||
async fn get_media_content(&self, _request: &MediaRequest) -> Result<Option<Vec<u8>>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
async fn remove_media_content(&self, request: &MediaRequest) -> Result<()> {
|
||||
self.media.lock().await.pop(&request.unique_key());
|
||||
|
||||
async fn remove_media_content(&self, _request: &MediaRequest) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_media_content_for_uri(&self, uri: &MxcUri) -> Result<()> {
|
||||
let mut media_store = self.media.lock().await;
|
||||
|
||||
let keys: Vec<String> = media_store
|
||||
.iter()
|
||||
.filter_map(
|
||||
|(key, _)| if key.starts_with(&uri.to_string()) { Some(key.clone()) } else { None },
|
||||
)
|
||||
.collect();
|
||||
|
||||
for key in keys {
|
||||
media_store.pop(&key);
|
||||
}
|
||||
|
||||
async fn remove_media_content_for_uri(&self, _uri: &MxcUri) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -1401,7 +1401,7 @@ mod tests {
|
||||
Ok(IndexeddbStateStore::builder().name(db_name).build().await?)
|
||||
}
|
||||
|
||||
statestore_integration_tests!();
|
||||
statestore_integration_tests!(with_media_tests);
|
||||
}
|
||||
|
||||
#[cfg(all(test, target_arch = "wasm32"))]
|
||||
@@ -1420,7 +1420,7 @@ mod encrypted_tests {
|
||||
Ok(IndexeddbStateStore::builder().name(db_name).passphrase(passphrase).build().await?)
|
||||
}
|
||||
|
||||
statestore_integration_tests!();
|
||||
statestore_integration_tests!(with_media_tests);
|
||||
}
|
||||
|
||||
#[cfg(all(test, target_arch = "wasm32"))]
|
||||
|
||||
@@ -1508,7 +1508,7 @@ mod tests {
|
||||
SledStateStore::builder().build().map_err(Into::into)
|
||||
}
|
||||
|
||||
statestore_integration_tests!();
|
||||
statestore_integration_tests!(with_media_tests);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -1521,7 +1521,7 @@ mod encrypted_tests {
|
||||
SledStateStoreBuilder::build_encrypted().map_err(Into::into)
|
||||
}
|
||||
|
||||
statestore_integration_tests!();
|
||||
statestore_integration_tests!(with_media_tests);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -506,12 +506,9 @@ async fn get_media_content() {
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/_matrix/media/r0/download/localhost/textfile"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_string("Some very interesting text."))
|
||||
.expect(2)
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
client.media().get_media_content(&request, true).await.unwrap();
|
||||
client.media().get_media_content(&request, true).await.unwrap();
|
||||
client.media().get_media_content(&request, false).await.unwrap();
|
||||
}
|
||||
|
||||
@@ -533,13 +530,11 @@ async fn get_media_file() {
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/_matrix/media/r0/download/example%2Eorg/image"))
|
||||
.respond_with(ResponseTemplate::new(200).set_body_raw("binaryjpegdata", "image/jpeg"))
|
||||
.expect(1)
|
||||
.named("get_file")
|
||||
.mount(&server)
|
||||
.await;
|
||||
|
||||
client.media().get_file(event_content.clone(), true).await.unwrap();
|
||||
client.media().get_file(event_content.clone(), true).await.unwrap();
|
||||
client.media().get_file(event_content.clone(), false).await.unwrap();
|
||||
|
||||
Mock::given(method("GET"))
|
||||
.and(path("/_matrix/media/r0/thumbnail/example%2Eorg/image"))
|
||||
@@ -556,7 +551,7 @@ async fn get_media_file() {
|
||||
.get_thumbnail(
|
||||
event_content,
|
||||
MediaThumbnailSize { method: Method::Scale, width: uint!(100), height: uint!(100) },
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user