Skip to content

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

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

Merged

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 3 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.
Copy link

codecov bot commented Mar 3, 2025

Codecov Report

Attention: Patch coverage is 85.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 86.11%. Comparing base (95b53d7) to head (9dc7a37).
Report is 38 commits behind head on main.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/event_cache/room/mod.rs 82.69% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4740      +/-   ##
==========================================
- Coverage   86.14%   86.11%   -0.04%     
==========================================
  Files         292      292              
  Lines       34295    34309      +14     
==========================================
+ Hits        29544    29545       +1     
- Misses       4751     4764      +13     

☔ 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).

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay. I've added a new commit (happy to squash it) that removes EventsPostProcessing and updates the documentation of with_events_mut.

@@ -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?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to go step-by-step: first the refactoring, then the fix (that's only possible because of the refactoring). Glad to merge these 2 patches in a single one when review will be finished.

Hywan added 8 commits March 5, 2025 09:23
…`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.
…onId`.

This patch updates `maybe_apply_new_redaction` to remove the first
`&RoomVersionId` argument. Indeed, due to the refactoring, it's now
possible for `maybe_apply_new_redaction` to read this value directly
from `Self::room_version`.
This patch removes the `EventsPostProcessing` type, it assumes
`with_events_muts` will always return events that will be post-process.
The case where `EventsPostProcessing::None` becomes a `vec![]`.
@Hywan Hywan force-pushed the fix-sdk-event-cache-maybe_apply_new_redaction branch from 13f9f6c to 9dc7a37 Compare March 5, 2025 09:19
@Hywan Hywan requested a review from bnjbvr March 5, 2025 09:20
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.

Nice, thank you!

@Hywan Hywan merged commit 8d8846a into matrix-org:main Mar 5, 2025
43 checks passed
@Hywan
Copy link
Member Author

Hywan commented Mar 5, 2025

I forgot to add the test… here it is, #4760!

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