fix(api): support server-side sorting for newest, oldest, and Z-A pagination in link listing#308
Open
wulukewu wants to merge 2 commits into
Open
fix(api): support server-side sorting for newest, oldest, and Z-A pagination in link listing#308wulukewu wants to merge 2 commits into
wulukewu wants to merge 2 commits into
Conversation
Add sort query param to /api/link/list for createdAt_desc/asc sorting. List all KV keys on the server, sort by createdAt, and return paginated results so the first page always contains the newest links. Previously KV.list() returned pages in alphabetical key order, and client-side sorting only applied to already-loaded links. This caused two bugs: 1. Newest links (alphabetically late slugs) were invisible until all pages loaded via infinite scroll. 2. KV.list() cursor pagination skipped links created before the cursor position, causing them to never appear. Closes #KV-cursor-newlink-bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
KV.list()returns pages in alphabetical key order, but the dashboard's sorting for "newest", "oldest", and "Z-A" (za) was done client-side on already-loaded data only. This means:KV.list()cursor represents an alphabetical position. Any link created/sorted that falls before the cursor is never returned in subsequent pages during pagination.Solution
Add a
sortquery parameter toGET /api/link/listsupportingslug_asc(default),slug_desc(Z-A),createdAt_desc(newest), andcreatedAt_asc(oldest).slug_asc(A-Z), the server continues to use nativeKV.list()for optimal performance.slug_desc,createdAt_desc, andcreatedAt_asc, the server:KV.list()pages of 1000){createdAt}::{slug}for creation date sorting{slug}for Z-A (slug_desc) sortingThe client-side sort for
newest/oldestis removed, and all custom sorting relies on the server-side pagination.Changes
server/utils/link-store.ts— addlistLinksSorted()supporting custom sorting criteriaserver/api/link/list.get.ts— addsortquery param and route tolistLinksSorted()orlistLinks()layers/dashboard/app/components/dashboard/links/Index.vue— pass sort, reset list on sort change