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

Paging3: Discussion #2913

Closed
wants to merge 2 commits into from
Closed

Paging3: Discussion #2913

wants to merge 2 commits into from

Conversation

vanniktech
Copy link
Contributor

@vanniktech vanniktech commented Mar 13, 2022

Follow up from:

https://github.com/cashapp/sqldelight/pull/2219/files#r825447672

I'm trying to upgrade from paging2 to paging3 and so far OffsetQueryPagingSource hasn't worked for me. With the changes below they do.

I'd like to discuss with others if my mental model of how paging should work is wrong or if the current implementation hasn't considered all use cases.

Tests should be failing. First want to discuss the change.

transacter.transactionWithResult {
val count = countQuery.executeAsOne()
if (count != 0L && key >= count) throw IndexOutOfBoundsException()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to remove this (https://github.com/cashapp/sqldelight/pull/2219/files#r825447672), consider the following scenario:

You have 3 items from your database. All are currently shown because some column = true when changing that particular column for instance for the last entry, the item should not be shown any longer since column = false. This used to work fine in paging2, but now it crashes here.

Removing it just works fine. The item won't be shown and my RecyclerView only has 2 items.

@@ -33,11 +33,13 @@ internal class OffsetQueryPagingSource<RowType : Any>(
override suspend fun load(
params: LoadParams<Long>
): LoadResult<Long, RowType> = withContext(dispatcher) {
val key = when {
params is LoadParams.Refresh -> (params.key ?: 0L) / params.loadSize * params.loadSize
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My Pager Config has a page size of 40. If I change the underlying data of item at key / index 3 and a LoadParams.Refresh is triggered. With the old behavior, data was reloaded however it was now using offset=3. This caused the recycler view to auto scroll for some reason that I don't understand. Also this wasn't happening with paging2.

After fiddling with it, I found out that when staying in the same offset range (offset=0) as earlier before, my item was instantly updated and there was no scrolling.

@AlecKazakova
Copy link
Collaborator

Thanks for doing this work - we have to do a similar thing on cash updating to paging3 so I'm going to take a thorough look tomorrow during work to make sure I understand the changes

@vanniktech
Copy link
Contributor Author

@AlecStrong have you had a chance to test this implementation in the cash app?

@AlecKazakova
Copy link
Collaborator

I have not

@veyndan veyndan mentioned this pull request Jul 28, 2022
@vanniktech
Copy link
Contributor Author

Superseded by #3396

@vanniktech vanniktech deleted the paging3 branch July 28, 2022 17:55
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.

None yet

2 participants