Closed allanconda-mercari closed 1 year ago
By default, ordering is not guaranteed. In the sample's case, Reddit backend does not guarantee order therefore the app maintains order with indexInResponse
which is based on insertion order.
The indexInResponse
logic is broken after updates but I have updated the sample app to track insertion order with Room's autoGenerated Int PrimaryKey
. On the query to return PagingSource, it will need to ORDER BY _id ASC
to ensure PagingSource always returns data in the same order.
I'm trying to understand how to keep the ordering from the backend into Room, and I noticed the variable
indexInResponse
was used for this exact use case. However, after the paging 3 migration in this codebase, this variable is now unused and returns 0 for all items, although it is still used inORDER BY
in the query.I need to do exactly this so I want to know whether insertion order is preserved now in Paging 3 making
indexInResponse
unnecessary. From checking Room-generated I don't see anything like this happening, and as far as I know, SQLite doesn't guarantee this, otherwise, a variable likeindexInResponse
would not be necessary in the first place even for Paging 2.Looking for clarification in this scenario, so comments around this are appreciated.