Repository navigation
open the All Prompts list sorted by visibility score, highest first - #714
Conversation
…descending - Default `activeSort` state to 'visibility' (descending) when no `sort` searchParam is present in URL - Ensure Visibility column header displays as active with descending chevron indicator on initial load - Remove fallback sorting by `createdAt` in favor of unified `compareNullsLast` comparator - Preserve bottom placement for un-tracked prompts (null visibility scores) - Maintain explicit URL searchParam precedence and toggle-to-asc behavior on header re-click
gkhngyk
left a comment
There was a problem hiding this comment.
Correct and minimal — four lines of real change, and it lands on the part of the issue that was easy to get wrong.
That part being the header indicator. Making only the fallback comparison sort by visibility would have left the table visibly ordered while every header still read as unsorted, so the first click on Visibility would appear to do nothing. Defaulting activeSort itself rather than the comparator is exactly right: SortableHead computes active from it, so the chevron and aria-sort="descending" come along for free, and handleSort still toggles to ascending on re-click because it compares against the same value.
Things I checked beyond the diff:
- No reshuffle on load. I wondered whether the table could render with
visibilitystill empty — every score would read as null, sort would be a no-op, and the rows would jump once the data arrived. It can't:setAllPromptsandsetVisibilityare assigned together andloadingonly clears afterwards, so the table never renders against a half-populated state. - Ties behave sensibly.
compareNullsLastreturns 0 for equal values andArray.prototype.sortis stable, so prompts on the same score keep the order they arrived in — which iscreated_atdescending from the server. Newest-first survives as the implicit tiebreak rather than being lost outright. - URL precedence and null placement are untouched, as intended: an explicit
?sort=/?dir=still wins, and untracked prompts stay at the bottom in both directions. yarn typecheck,format:check,lintandtestall clean locally; the six lint warnings are pre-existing elsewhere in the tree.
Two non-blocking notes, neither worth another push:
SortableHead still types activeSort as AllPromptsSortKey | null. Harmless, but the null case is now unreachable and tightening it would document that.
Sorting by date is no longer reachable at all, since there is no createdAt sort key — so a user who has just added twenty prompts can't bring them to the top. That is the consequence the issue signed off on, and the right answer if it turns out to bother people is surfacing untracked prompts rather than restoring the old default. Flagging it only so it isn't mistaken for a regression later.
Approving. Thanks for keeping the diff this tight.
…row cap (#740) The skip added in #739 read one row per *citation*, not per answer: 200 answers matched 1,591 rows in production, and PostgREST silently caps an un-paginated select at 1,000. Everything past that first page looked unstored, was reprocessed, and had its writes discarded as duplicates — so a repair run reported thousands of citations written while the table did not move at all. The same trap as #714 and #716, and this file now says so. The lookup is paginated. A short page is the end-of-results signal, which is why it reads in exactly PostgREST's own page size. The reporting that hid it is fixed too. persistCitationRows counted the rows it attempted rather than the rows that landed, so duplicates counted as writes. The upsert now returns what it inserted, and the function separates three outcomes that were previously one number: n rows inserted 0 nothing new — every row was already there, which is what --force produces on every answer it revisits null nothing stored, retry Conflating 0 with failure would have made --force report every answer as broken; conflating failure with 0 is what let the original 228 lost answers look like a healthy run. Refs #732
…ing past 50 prompts (#747) The Prompts page sent every unanalyzed prompt inline in one request, and the route refused more than 50 of them. A brand with 100 active prompts was shown an "Analyze 100 prompts" button that could only ever return 400, and the page turned the reason into "Volume analysis failed" — so the one system that knew what was wrong never said it. Raising the cap alone would not have worked. Each prompt costs an LLM call plus a DataForSEO call and they run in order, measured at a 6.4s median across 1,215 consecutive rows: about eleven minutes for 100 prompts, far past what a request can be held open for. So the brand, not a list of prompts, is now the unit of work. The route starts the run and returns 202; the page follows a status endpoint and shows real progress ("Analyzing 32/100..."). Each prompt is saved as it lands, so a closed tab costs nothing already done. Quota still counts one run per click. Along the way, the prompt reads no longer assemble a list of ids to filter on and no longer trust an un-paginated select — the two shapes that lost data in #714, #740 and #741, and that a 1000-prompt brand sits exactly on the edge of. Inactive prompts are now skipped rather than spending an LLM call and a DataForSEO call on a row no surface reads. Failures reach the user as wording chosen for a person. The server's text names batch sizes, upstream APIs and Postgres columns; none of it is shown. The actions return a small set of codes instead of throwing, which also fixes the quota message never appearing — it was matched on text that Next.js redacts in production.
activeSortstate to 'visibility' (descending) when nosortsearchParam is present in URLcreatedAtin favor of unifiedcompareNullsLastcomparatorCloses #712