Rewrites the internal/db/queries comments to rule 32 and regenerates dbq, whose doc comments and embedded SQL carry them. The bugs behind the tiered mixes, the md5 order seed, the score bands and the round-robin arms are restated as the constraint each one enforces; counts from one library and stale cross-references are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.2 KiB
SQL
33 lines
1.2 KiB
SQL
-- name: InsertLibraryChange :exec
|
|
INSERT INTO library_changes (entity_type, entity_id, op)
|
|
VALUES ($1, $2, $3);
|
|
|
|
-- name: InsertLibraryChanges :exec
|
|
-- Batch form, for a mutation that touches many rows at once (the scan's
|
|
-- reconcile pass can mark up to a quarter of a library missing in one go). A
|
|
-- loop of single inserts would be thousands of round-trips inside a scan that
|
|
-- is already the slow path.
|
|
INSERT INTO library_changes (entity_type, entity_id, op)
|
|
SELECT sqlc.arg(entity_type)::text,
|
|
unnest(sqlc.arg(entity_ids)::text[]),
|
|
sqlc.arg(op)::text;
|
|
|
|
-- name: GetLibraryChangesSince :many
|
|
SELECT id, entity_type, entity_id, op, changed_at
|
|
FROM library_changes
|
|
WHERE id > $1
|
|
ORDER BY id ASC
|
|
LIMIT $2;
|
|
|
|
-- name: GetMaxLibraryChangeCursor :one
|
|
SELECT COALESCE(MAX(id), 0)::BIGINT FROM library_changes;
|
|
|
|
-- name: GetMinLibraryChangeCursor :one
|
|
SELECT COALESCE(MIN(id), 0)::BIGINT FROM library_changes;
|
|
|
|
-- name: DeleteOldLibraryChanges :execrows
|
|
-- Removes library_changes rows older than the given cutoff. Run from
|
|
-- the sync compactor goroutine on a daily tick. Returns the number of
|
|
-- rows deleted so the worker can log meaningful progress.
|
|
DELETE FROM library_changes WHERE changed_at < $1;
|