Embed all necessary data in pagination cursors
Requirements
- [X] Is this a feature request? For questions or discussions use https://lemmy.ml/c/lemmy_support
- [X] Did you check to see if this issue already exists?
- [X] Is this only a feature request? Do not put multiple feature requests in one issue.
- [X] Is this a backend issue? Use the lemmy-ui repo for UI / frontend issues.
- [X] Do you agree to follow the rules in our Code of Conduct?
Is your proposal related to a problem?
Using the ID makes an additional database query necessary and doesn't work if the referenced item is purged
Describe the solution you'd like.
For the pagination cursor, instead of using the ID, use the json serialization or something similar of the cursor data struct (currently it's the whole aggregates struct)
Describe alternatives you've considered.
Only include the fields used by the selected sort type (more complicated)
Additional context
No response
Not convinced this would be a good idea. The current system works perfectly fine, a single additional O(1) query is basically irrelevant compared to the cost of a post view query. Cursors are not supposed to be long-lived, and an exact post being purged during pagination is very unlikely.
Changing this is a large jump in complexity that needs to be implemented and maintained, and the size of the cursor would be huge.
a single additional O(1) query is basically irrelevant compared to the cost of a post view query
Depends on the amount of network latency with the database, which is potentially significant in a horizontally scaled setup
With #5429 I've also made it so that cursor strings can contain multiple keys if necessary, but I agree pre-fetching the cursor data from keys is better than trying to serialize potentially large structs into strings.