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

feat(sdk): Add LinkedChunk::remove_item_at #4173

Merged

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Oct 28, 2024

This patch should be reviewed commit-by-commit.

The idea is to implement LinkedChunk::remove_item_at, which removes an item at a specific position. This new feature propagates to Update with Update::RemoveItem and to UpdateToVectorDiff which can emit a VectorDiff::Remove.

One bug has been found and fixed in UpdateToVectorDiff, which no impact on the SDK so far since this API is not yet used.


@Hywan Hywan requested a review from a team as a code owner October 28, 2024 10:44
@Hywan Hywan requested review from andybalaam and removed request for a team October 28, 2024 10:44
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

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

Project coverage is 84.82%. Comparing base (77b3aa8) to head (74283ea).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
...tes/matrix-sdk/src/event_cache/linked_chunk/mod.rs 80.00% 6 Missing ⚠️
...trix-sdk/src/event_cache/linked_chunk/as_vector.rs 92.10% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4173      +/-   ##
==========================================
- Coverage   84.82%   84.82%   -0.01%     
==========================================
  Files         269      269              
  Lines       28963    29007      +44     
==========================================
+ Hits        24569    24605      +36     
- Misses       4394     4402       +8     

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

Hywan added 6 commits October 28, 2024 13:51
This patch adds the `LinkedChunk::remove_item_at` method, along with
`Update::RemoveItem` variant.
This is only code move, nothing has changed.
This is a clean up patch, nothing fancy.
This is another clean up patch.
This patch fixes a bug in an optimisation inside `UpdateToVectorDiff`
when an `Update::PushItems` is handled. It can sometimes create
`VectorDiff::Append` instead of a `VectorDiff::Insert`. The tests will
be part of the next patch.
…ateToVectorDiff`.

This patch implements the support of `Update::RemoveItem` inside
`UpdateToVectorDiff` to emit a `VectorDiff::Remove`.
@Hywan Hywan force-pushed the feat-sdk-event-cache-linked-chunk-remove-item-at branch from e95830a to 74283ea Compare October 28, 2024 12:51
Copy link
Member

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

// can remove it.
if can_unlink_chunk && chunk.is_first_chunk().not() {
// Unlink `chunk`.
chunk.unlink(&mut self.updates);
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we should be able to share this logic with LinkedChunk::replace_gap_at maybe?

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 note that on my todo list.

}

// Remove the first item of the first chunk, 3 times. The chunk is empty after
// that. The chunk is NOT removed because it's the first chunk.
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer separate tests for each of these scenarios, but I'm not insisting on it.

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 was hesitant on this one, the balance is more code vs. more tests. I usually prefer small unit tests though. I note that on my to do list. Thanks for the feedback.

@Hywan Hywan merged commit b62661b into matrix-org:main Oct 28, 2024
40 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