-
Notifications
You must be signed in to change notification settings - Fork 260
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
feat(ui): Timeline
consumes updates as VectorDiff
s from the EventCache
#4408
feat(ui): Timeline
consumes updates as VectorDiff
s from the EventCache
#4408
Conversation
c44c178
to
0ca5852
Compare
92cdf2e
to
0aa794f
Compare
0aa794f
to
3821440
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, exciting to see this coming through! I've annotated the important review comments with a
/// Use `VectorDiff`s as the new “input mechanism” for the `Timeline`. | ||
/// | ||
/// Read `TimelineSettings::vectordiffs_as_inputs` to learn more. | ||
pub fn with_vectordiffs_as_inputs(mut self) -> Self { | ||
self.settings.vectordiffs_as_inputs = true; | ||
self | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventCache
, and that the EC would choose to emit AddTimelineItems
or UpdateTimelineItems
based on the feature flag? Otherwise, any other user of the event cache, that's not the timeline, has to implement the same filtering mechanism.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this quite a lot too.
First off, this setting is temporary. It's gonna be removed as soon as we consider RoomEventCacheUpdate::UpdateTimelineEvents
stable and we want to switch to it. The other variant, AddTimelineEvents
will be removed at the same time.
Second, we have validated this approach during our team meeting :-p.
Third, while I share your concerns, putting the setting on the EventCache
makes it so the Timeline
can receive both inputs at the same time (AddTimelineEvents
and UpdateTimelineEvents
), which can create a lot of confusion and inconsistent state.
Fourth, this setting is used to decide if the Timeline
has to apply its own deduplication mechanism or not:
- with
AddTimelineEvents
: yes, it has to, - with
UpdateTimelineEvents: no, because it's expected to be handle by the
VectorDiff. Putting the settings on the
EventCachemakes it way more difficult for the
Timelineto decide. Actually, it requires a setting in the
Timeline` anyway.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Third, while I share your concerns, putting the setting on the EventCache makes it so the Timeline can receive both inputs at the same time (AddTimelineEvents and UpdateTimelineEvents), which can create a lot of confusion and inconsistent state.
No: the idea is that, the EventCache would emit AddTimelineEvents
if !feature_flag
, and emit UpdateTimelineEvents
if feature_flag
, not both at the same time.
Re: fourth, you're right the timeline would need to get this information; it's relatively trivial to add a getter on the feature flag in the event cache, and get the feature flag value from the TimelineBuilder
.
(Re: second, sometimes people change their mind when they realize they were wrong, and I definitely was when I validated it 😇)
Overall, I would even call for not having a feature flag at all, and remove the previous code entirely, but I understand that it's a big change, and it would be nice to test in isolation (especially before the EOY holidays). So my preference would be to have a feature flag on the EventCache, for consistency (it would also simplify code at the FFI layer, I suppose), but we can probably live with the feature flag on the Timeline, if you strongly prefer it.
crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs
Outdated
Show resolved
Hide resolved
(Extra review comment, since I just thought about it: might be nice to expose the feature flag at the FFI layer, for testing purposes?) |
The FFI part will be done in another PR. I wanted to keep this PR as small and simple as possible first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, thanks.
I think it might be nice to have the FFI feature flag as soon as possible, and/or enable the feature flag if the event cache storage feature flag is set; otherwise, it's expected that this will break the caching feature (now that #4427 has landed).
Thank you, great work there!!
This patch adds `with_vectordiffs_as_inputs` on `TimelineBuilder` and `vectordiffs_as_inputs` on `TimelineSettings`. This new flag allows to transition from one system to another for the `Timeline`, when enabled, the `Timeline` will accept `VectorDiff<SyncTimelineEvent>` for the inputs instead of `Vec<SyncTimelineEvent>`.
2a0277a
to
bbf88a9
Compare
Okay so The |
This patch adds a new variant to `RoomEventCacheUpdate`, namely `UpdateTimelineEvents. It's going to replace `AddTimelineEvents` soon once it's stable enough. This is a transition. They are read by the `Timeline` if and only if `TimelineSettings::vectordiffs_as_inputs` is turned on.
…handle_remote_events_with_diffs`. This patch updates `TimelineStateTransaction::handle_remote_events_with_diffs` to support `VectorDiff::Append`.
…n::handle_remote_events_with_diffs`. This patch updates `TimelineStateTransaction::handle_remote_events_with_diffs` to support `VectorDiff::PushFront`.
…::handle_remote_events_with_diffs`. This patch updates `TimelineStateTransaction::handle_remote_events_with_diffs` to support `VectorDiff::PushBack`.
…andle_remote_events_with_diffs`. This patch updates `TimelineStateTransaction::handle_remote_events_with_diffs` to support `VectorDiff::Clear`.
This patch adds the `ObservavbleItems::insert_remote_event` method. This is going to be useful to implement `VectorDiff::Insert` inside `TimelineStateTransaction::handle_remote_events_with_diffs`.
This patch adds the `AllRemoteEvents::range` method. This is going to be useful to support `VectorDiff::Insert` inside `TimelineStateTransaction::handle_remote_events_with_diffs`.
…handle_remote_events_with_diffs`. This patch updates `TimelineStateTransaction::handle_remote_events_with_diffs` to support `VectorDiff::Insert`.
…:handle_remote_events_with_diffs`. This patch updates `TimelineStateTransaction::handle_remote_events_with_diffs` to support `VectorDiff::Remove,`.
The `Timeline` has its own remote event deduplication mechanism. But we are transitioning to receive updates from the `EventCache` via `VectorDiff`, which are emitted via `RoomEvents`, which already runs its own deduplication mechanism (`matrix_sdk::event_cache::Deduplicator`). Deduplication from the `EventCache` will generate `VectorDiff::Remove` for example. It can create a conflict with the `Timeline` deduplication mechanism. This patch updates the deduplication mechanism from the `Timeline` when adding or updating remote events to be conditionnal: when `TimelineSettings::vectordiffs_as_inputs` is enabled, the deduplication mechanism of the `Timeline` is silent, it does nothing, otherwise it runs.
This patch updates this branch to `main` where `DayDivider` has been renamed `DateDivider`.
Since we have added a new variant to `RoomEventCacheUpdate`, a macro hits the recursion limit. It needs to be updated in order for tests to run again.
…uickly. This patch adds a trick around `SyncTimelineEvent` to avoid reaching the `recursion_limit` too quickly. Read the documentation in this patch to learn more.
A previous patch deduplicates the remote events conditionnally. This patch does the same but for timeline items. The `Timeline` has its own deduplication algorithm (for remote events, and for timeline items). The `Timeline` is about to receive its updates via the `EventCache` which has its own deduplication mechanism (`matrix_sdk::event_cache::Deduplicator`). To avoid conflicts between the two, we conditionnally deduplicate timeline items based on `TimelineSettings::vectordiffs_as_inputs`. This patch takes the liberty to refactor the deduplication mechanism of the timeline items to make it explicit with its own methods, so that it can be re-used for `TimelineItemPosition::At`. A specific short-circuit was present before, which is no more possible with the rewrite to a generic mechanism. Consequently, when a local timeline item becomes a remote timeline item, it was previously updated (via `ObservableItems::replace`), but now the local timeline item is removed (via `ObservableItems::remove`), and then the remote timeline item is inserted (via `ObservableItems::insert`). Depending of whether a virtual timeline item like a date divider is around, the position of the removal and the insertion might not be the same (!), which is perfectly fine as the date divider will be re-computed anyway. The result is exactly the same, but the `VectorDiff` updates emitted by the `Timeline` are a bit different (different paths, same result). This is why this patch needs to update a couple of tests.
This patch allows the paginated events of a `Timeline` to be received via `RoomEventCacheUpdate::UpdateTimelineEvents` as `VectorDiff`s.
…ache storage is enabled. This patch automatically enables `TimelineSettings::vectordiffs_as_inputs` if and only if the event cache storage is enabled.
5bb2b11
to
70c3d2a
Compare
70c3d2a
to
60fefdd
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4408 +/- ##
==========================================
- Coverage 85.41% 85.03% -0.38%
==========================================
Files 283 283
Lines 31559 31736 +177
==========================================
+ Hits 26955 26988 +33
- Misses 4604 4748 +144 ☔ View full report in Codecov by Sentry. |
This patch should be reviewed commit by commit.
With this patch, the
Timeline
is able to consumeVectorDiff
s from theEventCache
viaRoomEventCacheUpdate::UpdateTimelineEvents
instead ofRoomEventCacheUpdate::AddTimelineItems
.It has many advantages:
Timeline
has a unique entry point instead of many:Timeline
viaRoomEventCacheUpdate
, and the (back-)pagination was adding events via internalTimeline
API,RoomEventCacheUpdate
,EventCache
persistent storage,RoomEventCacheView
, a new API we are working on to improve performance of multipleTimeline
s for the same room (like Media gallery, Thread, Pinned event, and the regular Timeline).Timeline
does not need to run a deduplication over events, since theEventCache
already has its ownDeduplicator
(note that the old dedup mechanism of theTimeline
must be kept for permalink support for the moment)AllRemoteEvents
type #4370EventCache
storage #3280RoomEventCache
'sVectorDiff
toTimeline
#3512