diff --git a/crates/matrix-sdk-base/src/event_cache/store/media/media_service.rs b/crates/matrix-sdk-base/src/event_cache/store/media/media_service.rs index 8bd183adb..508eb3246 100644 --- a/crates/matrix-sdk-base/src/event_cache/store/media/media_service.rs +++ b/crates/matrix-sdk-base/src/event_cache/store/media/media_service.rs @@ -15,9 +15,14 @@ use std::{fmt, sync::Arc}; use async_trait::async_trait; -use matrix_sdk_common::{locks::Mutex, AsyncTraitDeps}; +use matrix_sdk_common::{ + executor::{spawn, JoinHandle}, + locks::Mutex, + AsyncTraitDeps, SendOutsideWasm, SyncOutsideWasm, +}; use ruma::{time::SystemTime, MxcUri}; use tokio::sync::Mutex as AsyncMutex; +use tracing::error; use super::MediaRetentionPolicy; use crate::{event_cache::store::EventCacheStoreError, media::MediaRequestParameters}; @@ -41,6 +46,15 @@ struct MediaServiceInner { /// A mutex to ensure a single cleanup is running at a time. cleanup_guard: AsyncMutex<()>, + + /// The time of the last media cache cleanup. + last_media_cleanup_time: Mutex>, + + /// The [`JoinHandle`] for an automatic media cleanup task. + /// + /// Used to ensure that only one automatic cleanup is running at a time, and + /// to stop the cleanup when the [`MediaServiceInner`] is dropped. + automatic_media_cleanup_join_handle: Mutex>>, } impl MediaService { @@ -61,7 +75,7 @@ impl Default for MediaService { impl