[_]: feat/allow-lastId-param-when-listing-files #849
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


What
Allow an optional
lastIdparameter onGET /files. This parameter will be used instead ofoffset. If both are provided,offsetwill be ignored whenlastIdis present. An index to leverage the current query is also being added.Why
We have relied on
OFFSETfor a long time, and pagination is becoming a performance bottleneck. Large offsets grow almost linearly with the dataset size, making pagination for accounts with hundreds of thousands of files non-scalable.The idea is to introduce a
WHERE >clause based on the file UUID. When used together with sorting by the same UUID, this effectively switches the pagination strategy to cursor-based pagination, which is significantly more efficient and offers near-constant performance at the database level.Proof
Same query, with real data.
EXPLAIN ANALYZEwith OFFSET:By using the WHERE:
How
Allow the new parameter and apply it in the
WHEREclause so the database can leverage the index to skip records efficiently, instead of usingOFFSET, which requires scanning and discarding rows explicitly. Also, adding a migration to leverage the current query makes this faster.