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 RoomPagination::run_backwards(…, until) #3472

Merged

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented May 28, 2024

This patch adds a new argument to RoomPagination::run_backwards: until. It becomes:

pub async fn run_backwards<Until, Break, UntilFuture>(
    &self,
    batch_size: u16,
    mut until: Until,
) -> Result<Break>
where
    Until: FnMut(BackPaginationOutcome, TimelineHasBeenResetWhilePaginating) -> UntilFuture,
    UntilFuture: Future<Output = ControlFlow<Break, ()>>,

The idea behind until is to run pagination until until returns ControlFlow::Break, otherwise it continues paginating.

This is useful is many scenearii (cf. the documentation). This is also and primarily the first step to stop adding events directly from the pagination, and starts adding events only and strictly only from event_cache::RoomEventCacheUpdate (again, see the TODO in the documentation). This is not done in this patch for the sake of ease of review.


@Hywan Hywan requested a review from a team as a code owner May 28, 2024 07:10
@Hywan Hywan requested review from bnjbvr and removed request for a team May 28, 2024 07:10
@Hywan Hywan mentioned this pull request May 28, 2024
37 tasks
Copy link

codecov bot commented May 28, 2024

Codecov Report

Attention: Patch coverage is 92.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 83.28%. Comparing base (1dc3709) to head (9a1de1d).
Report is 33 commits behind head on main.

Files Patch % Lines
crates/matrix-sdk/src/event_cache/pagination.rs 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3472      +/-   ##
==========================================
- Coverage   83.29%   83.28%   -0.02%     
==========================================
  Files         248      248              
  Lines       25236    25243       +7     
==========================================
+ Hits        21021    21024       +3     
- Misses       4215     4219       +4     

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

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.

Cheers! This may require a bit more testing…

Hywan added 3 commits May 28, 2024 10:55
This patch adds a new argument to `RoomPagination::run_backwards`:
`until`. It becomes:

    pub async fn run_backwards<F, B, Fut>(&self,
        batch_size: u16,
        mut until: F
    ) -> Result<B>
    where
        F: FnMut(BackPaginationOutcome) -> Fut,
        Fut: Future<Output = ControlFlow<B, ()>>,

The idea behind `until` is to run pagination _until_ `until` returns
`ControlFlow::Break`, otherwise it continues paginating.

This is useful is many scenearii (cf. the documentation). This is
also and primarily the first step to stop adding events directly from
the pagination, and starts adding events only and strictly only from
`event_cache::RoomEventCacheUpdate` (again, see the `TODO` in the
documentation). This is not done in this patch for the sake of ease
of review.
This patch adds a new argument to the `until` argument closure of
`RoomPagination::run_backwards`: `timeline_has_been_reset`, which
designates when the timeline has been reset.

A test has been updated accordingly.
This patch adds a test for `until` when it returns
`ControlFlow::Continue` multiple times instead of `ControlFlow::Break`
immediately.
@Hywan Hywan force-pushed the feat-sdk-event-cache-pagination-through-update branch from bb0f598 to 7377971 Compare May 28, 2024 09:36
@Hywan Hywan requested a review from bnjbvr May 28, 2024 09:37
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.

yay

@Hywan Hywan merged commit 72314f1 into matrix-org:main May 28, 2024
36 of 38 checks passed
@bnjbvr
Copy link
Member

bnjbvr commented May 28, 2024

This didn't pass tests on CI, and it's been force-merged. Will revert because it was incorrectly merged.

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