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): Do not always remove empty chunks from LinkedChunk #4216

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Nov 5, 2024

This patch introduces EmptyChunk, a new enum used to represent whether empty chunks must be removed/unlink or kept from the LinkedChunk. It is used by LinkedChunk::remove_item_at.

Why is it important? For example, imagine the following situation:

  • one inserts a single event in a new chunk (possible if a (sliding) sync is done with timeline_limit=1),
  • one inserts many events at the position of the previous event, with one of the new events being a duplicate of the first event (possible if a (sliding) sync is done with timeline_limit=10 this time),
  • prior to this patch, the older event was removed, resulting in an empty chunk, which was removed from the LinkedChunk, invalidating the insertion position!

So, with this patch:

  • RoomEvents::remove_events does remove empty chunks, but
  • RoomEvents::remove_events_and_update_insert_position does NOT remove empty chunks, they are kept in case the position wants to insert in this same chunk.

@Hywan Hywan requested a review from a team as a code owner November 5, 2024 12:15
@Hywan Hywan requested review from poljar and removed request for a team November 5, 2024 12:15
Copy link

codecov bot commented Nov 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.89%. Comparing base (04275d7) to head (3895f75).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4216      +/-   ##
==========================================
+ Coverage   84.86%   84.89%   +0.02%     
==========================================
  Files         272      272              
  Lines       29167    29171       +4     
==========================================
+ Hits        24752    24764      +12     
+ Misses       4415     4407       -8     

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

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Makes sense, left a small nit.

This patch introduces `EmptyChunk`, a new enum used to represent whether
empty chunks must be removed/unlink or kept from the `LinkedChunk`. It
is used by `LinkedChunk::remove_item_at`.

Why is it important? For example, imagine the following situation:

- one inserts a single event in a new chunk (possible if a (sliding)
  sync is done with `timeline_limit=1`),
- one inserts many events at the position of the previous event,
  with one of the new events being a duplicate of the first event
  (possible if a (sliding) sync is done with `timeline_limit=10` this
  time),
- prior to this patch, the older event was removed, resulting in an
  empty chunk, which was removed from the `LinkedChunk`, invalidating
  the insertion position!

So, with this patch:

- `RoomEvents::remove_events` does remove empty chunks, but
- `RoomEvents::remove_events_and_update_insert_position` does NOT remove
  empty chunks, they are kept in case the position wants to insert in this
  same chunk.
@Hywan Hywan force-pushed the fix-sdk-event-cache-linked-chunk-do-not-delete-empty-chunk branch from 6327f98 to 3895f75 Compare November 5, 2024 15:37
@Hywan Hywan enabled auto-merge (rebase) November 5, 2024 15:41
@Hywan Hywan merged commit 933033c into matrix-org:main Nov 5, 2024
39 checks passed
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