Skip to content

Commit 33d691a

Browse files
authored
Merge pull request #4571 from zecakeh/media-retention-policy
feat: Add MediaRetentionPolicy to the EventCacheStore, take 2
2 parents 31e7ec1 + c2f39c1 commit 33d691a

File tree

17 files changed

+3114
-113
lines changed

17 files changed

+3114
-113
lines changed

crates/matrix-sdk-base/CHANGELOG.md

+27-11
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,35 @@ All notable changes to this project will be documented in this file.
66

77
## [Unreleased] - ReleaseDate
88

9-
### Breaking changes
10-
11-
- Replaced `Room::compute_display_name` with the reintroduced `Room::display_name()`. The new
12-
method computes a display name, or return a cached value from the previous successful computation.
13-
If you need a sync variant, consider using `Room::cached_display_name()`.
14-
- [**breaking**]: The reexported types `SyncTimelineEvent` and `TimelineEvent` have been fused into a single type
15-
`TimelineEvent`, and its field `push_actions` has been made `Option`al (it is set to `None` when
16-
we couldn't compute the push actions, because we lacked some information).
17-
([#4568](https://github.com/matrix-org/matrix-rust-sdk/pull/4568))
18-
199
### Features
2010

21-
### Bug Fixes
11+
- [**breaking**] `EventCacheStore` allows to control which media content is
12+
allowed in the media cache, and how long it should be kept, with a
13+
`MediaRetentionPolicy`:
14+
- `EventCacheStore::add_media_content()` has an extra argument,
15+
`ignore_policy`, which decides whether a media content should ignore the
16+
`MediaRetentionPolicy`. It should be stored alongside the media content.
17+
- `EventCacheStore` has four new methods: `media_retention_policy()`,
18+
`set_media_retention_policy()`, `set_ignore_media_retention_policy()` and
19+
`clean_up_media_cache()`.
20+
- `EventCacheStore` implementations should delegate media cache methods to the
21+
methods of the same name of `MediaService` to use the `MediaRetentionPolicy`.
22+
They need to implement the `EventCacheStoreMedia` trait that can be tested
23+
with the `event_cache_store_media_integration_tests!` macro.
24+
([#4571](https://github.com/matrix-org/matrix-rust-sdk/pull/4571))
25+
26+
### Refactor
27+
28+
- [**breaking**] Replaced `Room::compute_display_name` with the reintroduced
29+
`Room::display_name()`. The new method computes a display name, or return a
30+
cached value from the previous successful computation. If you need a sync
31+
variant, consider using `Room::cached_display_name()`.
32+
([#4470](https://github.com/matrix-org/matrix-rust-sdk/pull/4470))
33+
- [**breaking**]: The reexported types `SyncTimelineEvent` and `TimelineEvent`
34+
have been fused into a single type `TimelineEvent`, and its field
35+
`push_actions` has been made `Option`al (it is set to `None` when we couldn't
36+
compute the push actions, because we lacked some information).
37+
([#4568](https://github.com/matrix-org/matrix-rust-sdk/pull/4568))
2238

2339
## [0.9.0] - 2024-12-18
2440

crates/matrix-sdk-base/src/event_cache/store/integration_tests.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use ruma::{
3232
push::Action, room_id, uint, RoomId,
3333
};
3434

35-
use super::DynEventCacheStore;
35+
use super::{media::IgnoreMediaRetentionPolicy, DynEventCacheStore};
3636
use crate::{
3737
event_cache::{Event, Gap},
3838
media::{MediaFormat, MediaRequestParameters, MediaThumbnailSettings},
@@ -168,7 +168,9 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
168168
);
169169

170170
// Let's add the media.
171-
self.add_media_content(&request_file, content.clone()).await.expect("adding media failed");
171+
self.add_media_content(&request_file, content.clone(), IgnoreMediaRetentionPolicy::No)
172+
.await
173+
.expect("adding media failed");
172174

173175
// Media is present in the cache.
174176
assert_eq!(
@@ -196,7 +198,7 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
196198
);
197199

198200
// Let's add the media again.
199-
self.add_media_content(&request_file, content.clone())
201+
self.add_media_content(&request_file, content.clone(), IgnoreMediaRetentionPolicy::No)
200202
.await
201203
.expect("adding media again failed");
202204

@@ -207,9 +209,13 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
207209
);
208210

209211
// Let's add the thumbnail media.
210-
self.add_media_content(&request_thumbnail, thumbnail_content.clone())
211-
.await
212-
.expect("adding thumbnail failed");
212+
self.add_media_content(
213+
&request_thumbnail,
214+
thumbnail_content.clone(),
215+
IgnoreMediaRetentionPolicy::No,
216+
)
217+
.await
218+
.expect("adding thumbnail failed");
213219

214220
// Media's thumbnail is present.
215221
assert_eq!(
@@ -225,9 +231,13 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
225231
);
226232

227233
// Let's add another media with a different URI.
228-
self.add_media_content(&request_other_file, other_content.clone())
229-
.await
230-
.expect("adding other media failed");
234+
self.add_media_content(
235+
&request_other_file,
236+
other_content.clone(),
237+
IgnoreMediaRetentionPolicy::No,
238+
)
239+
.await
240+
.expect("adding other media failed");
231241

232242
// Other file is present.
233243
assert_eq!(
@@ -279,7 +289,9 @@ impl EventCacheStoreIntegrationTests for DynEventCacheStore {
279289
assert!(self.get_media_content(&req).await.unwrap().is_none(), "unexpected media found");
280290

281291
// Add the media.
282-
self.add_media_content(&req, content.clone()).await.expect("adding media failed");
292+
self.add_media_content(&req, content.clone(), IgnoreMediaRetentionPolicy::No)
293+
.await
294+
.expect("adding media failed");
283295

284296
// Sanity-check: media is found after adding it.
285297
assert_eq!(self.get_media_content(&req).await.unwrap().unwrap(), b"hello");

0 commit comments

Comments
 (0)