Skip to content

Commit fcbfaf8

Browse files
authored
Improve the snapshot list query (#1407)
1 parent 04ba19b commit fcbfaf8

2 files changed

Lines changed: 8 additions & 14 deletions

File tree

packages/db/queries/get_snapshots_with_cursor.sql

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ WHERE
2222
-- And NULL does not match with empty json
2323
s.metadata @> @metadata OR @metadata = '{}'::jsonb
2424
)
25-
AND (
26-
s.sandbox_started_at < @cursor_time
27-
OR
28-
(s.sandbox_started_at = @cursor_time AND s.sandbox_id > @cursor_id)
29-
)
25+
-- The order here is important, we want started_at descending, but sandbox_id ascending
26+
AND (s.sandbox_started_at, @cursor_id::text) < (@cursor_time, s.sandbox_id)
3027
AND NOT (s.sandbox_id = ANY (@snapshot_exclude_sbx_ids::text[]))
31-
ORDER BY s.sandbox_started_at DESC, s.sandbox_id
28+
ORDER BY s.sandbox_started_at DESC, s.sandbox_id ASC
3229
LIMIT $1;

packages/db/queries/get_snapshots_with_cursor.sql.go

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)