Repository navigation
fix(audit): sort every ClickHouse find by a total order - #14635
Conversation
Cursor paging over /v1/activities/events skipped and repeated rows. The
ClickHouse adapter only added an ORDER BY when the caller passed one, and
only appended the `id` tiebreak when a cursor was present. The first page of
an unordered list therefore came back in whatever order ClickHouse read the
parts, while the next page compared and sorted on `id DESC`; with an
explicit `orderDesc('time')` the first page broke ties on `time` arbitrarily
while the cursor page broke them on `id`. Either way the rows on page 2 were
not the rows after page 1.
find() now resolves one order for every non-random query, cursor or not:
newest first (`time DESC`) when none is given, always ending in `id` in the
direction of the last column. That matches the table's sort key
(tenant, time, id), so ClickHouse can still read in order.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No issues found — approved ✅. The change is purely additive test coverage for the audit ClickHouse adapter's cursor-based keyset pagination and ordering guarantees.
Reviewed commit: 405a72d |
🟢 Tier S · Ready to merge
ClickHouse audit Latest changes: The new commits add resolved sort columns to slim SELECT projections and add unit and E2E coverage for paging from those projected rows.
📂 Walkthrough · 3
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
The default order now sorts on `time`, so a row from a slim projection such as Query::select(['event']) carried `id` but not `time`, and passing it to cursorAfter() failed with "Cursor is missing required attribute 'time'". find() now projects every column it orders by alongside the forced `id` and `tenant`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
Cursor paging through the ClickHouse audit adapter (
/v1/activities/eventson Cloud) skipped and repeated rows.find()only emitted anORDER BYwhen the caller passed one, and only appended theidtiebreak when a cursor was present:ORDER BYat all (ClickHouse part-read order), page 2 filtered and sorted onid DESC. Page 2 was not "the rows after page 1".orderDesc('time'): page 1 broke ties ontimearbitrarily, the cursor page broke them onid, so rows sharing a timestamp were skipped or repeated.find()now resolves a single total order for every non-random query, cursor or not:time DESCwhen none is given, always ending inidin the direction of the last column. That is the table's sort key(tenant, time, id), so ClickHouse can still read in order.orderRandomis unchanged. Every ordered column is also projected, so a row from a slimQuery::select()can still be the next cursor.total=false(the other half of the QA report) is not in this PR: the adapter has no notion of totals, and Cloud already honourstotal=falseon/v1/activities/eventssince appwrite-labs/cloud#6595 (E2EtestListEventsSkipsTheCountWhenTotalIsFalse).Tests
Fixing layer (
packages/audit):testCursorAfterWithoutOrderVisitsEveryLogOncecursor-unordered-02,-00returned twicetestCursorAfterOnTiedOrderVisitsEveryLogOncecursor-tied-08,-10never returnedtestCursorBeforeWithoutOrderReturnsThePreviousPage07,06,05instead of01,03,05testFindWithoutOrderReturnsNewestFirstolder, newertestFindWithoutOrderSortsNewestFirstWithIdTiebreakORDER BYtestFindAppendsIdTiebreakToTheRequestedOrderORDER BY time ASConlytestFindCursorPageSortsByTheColumnsItComparesOnidonlytestFindCursorBeforeFlipsTheDefaultOrdertestCursorFromASlimProjectionPagesWithoutAnOrderCursor is missing required attribute 'time'(review finding)testFindProjectsTheOrderColumnsASlimSelectLeavesOuttestFindKeepsAnExplicitIdOrder,testFindRandomOrderHasNoTiebreakLocal runs: unit 93/93, ClickHouse E2E 80/80,
bin/monorepo check auditclean.The API-level E2E of the symptom lives in Cloud (
ListEventsCustomServerTest), which owns the only ClickHouse-backed list route; it lands with the Cloud bump.🤖 Generated with Claude Code