Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): maybe_apply_new_redaction updates in-store events #4740

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Mar 3, 2025

This is the last known task required after the event cache lazy-loading feature.

This is unblocked by #4708.

maybe_apply_new_redaction was looking for events only from RoomEvents, so only in-memory. And the redaction was only happening in-memory too. With this patch, maybe_apply_new_redaction handles in memory and in store.

This pull request should be reviewed patch by patch for the sake of clarity.

A clean up in the Deduplicator is possible by using the new EventLocation enum, but it's not part of this set of patches.


Hywan added 7 commits March 3, 2025 07:37
…sing`.

This patch updates the callback passed to `with_events_mut`. It now
returns an `EventsPostProcessing` which can automatically run the, now
inlined, `on_new_events`.

This patch updates where the `RoomVersionId` is also stored. It's not
held by `RoomEventCacheState` instead of `RoomEventCacheInner`.
…events.

This patch renames `sync_timeline_events` into `timeline_events`.
Moreover, this change has spotted a possible improvement
in `AllEventsCache` where it now receives events from
`collect_valid_and_duplicated_events`, which allows to only store valid
events in it.
…`RoomEventCacheState`.

This patch moves the `maybe_apply_new_redaction` method from
`RoomEvents` inside `RoomEventCacheState` so that it has an access
to the store (necessary for the next patch). This patch creates a new
`RoomEvents::replace_event_at` method, which is a thin wrapper around
`LinkedChunk::replace_item_at`.
This patch introduces `EventLocation` to know if an event has been found
in the memory (in `RoomEvents`) or in the store (in `EventCacheStore`).

This is used by the `RoomEventCacheState::find_event`.
This patch updates `maybe_apply_new_redaction` to use `find_event`, so
that the target event is looked up in memory or in the store.

The case where it is in the store is a simple `todo!()` for the moment.
I wanted to separate the update of the `maybe_apply_new_redaction`
signature from the `InStore` implementation. The method is now async and
returns a `Result`.
This patch updates `maybe_apply_new_redaction` so that it is able to
update/redact an event found in the store.
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

Attention: Patch coverage is 84.37500% with 10 lines in your changes missing coverage. Please review.

Project coverage is 86.12%. Comparing base (95b53d7) to head (13f9f6c).

Files with missing lines Patch % Lines
crates/matrix-sdk/src/event_cache/room/mod.rs 82.14% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4740      +/-   ##
==========================================
- Coverage   86.14%   86.12%   -0.03%     
==========================================
  Files         292      292              
  Lines       34295    34313      +18     
==========================================
+ Hits        29544    29552       +8     
- Misses       4751     4761      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hywan Hywan force-pushed the fix-sdk-event-cache-maybe_apply_new_redaction branch from cd19fdc to 9d021a8 Compare March 3, 2025 09:18
@Hywan Hywan marked this pull request as ready for review March 3, 2025 09:33
@Hywan Hywan requested a review from a team as a code owner March 3, 2025 09:33
@Hywan Hywan requested review from andybalaam and bnjbvr and removed request for a team and andybalaam March 3, 2025 09:33
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good! can you add an integration test, where the event is only in the store, and not in memory, please?

.expect("failed to remove an event")
.expect("failed to remove an event");

EventsPostProcessing::None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it change the test result if you let the post-processing happen? I think it'd be simpler to get rid of the variants, and not have the EventsPostProcessing type overall, by having the callback passed to with_events_mut always return the events, and with_events_mut always call on_new_events() (or the inlined version).

/// Replace event at a specified position.
///
/// `position` must point to a valid item, otherwise the method returns
/// `Err`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe precise which error, or rewrite as "the method returns an error"? It's a bit weird to just have Err in isolation.

@@ -1230,8 +1237,10 @@ mod private {

match post_processing {
EventsPostProcessing::HaveBeenInserted(events) => {
let room_version = self.room_version.clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cloning seems unnecessary here. In fact, maybe_apply_new_redaction could read the self.room_version itself, without having to receive it as a parameter.

Comment on lines 1355 to 1356
InMemory,
InStore,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be called Memory and Store, only? Would be more concise, and the enum's name already indicates it's a location. (Otherwise it's temping to read it as "where is the event location itself?".)

@@ -1337,7 +1337,11 @@ mod private {
.expect("should have been a valid position of an item");
}
EventLocation::InStore => {
todo!()
self.send_updates_to_store(vec![Update::ReplaceItem {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why to include the fix to your own previous commit as a separate commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants