Skip to content

refactor(api,search): drop status predicates — D1 holds only status='ok' - #146

Merged
remcovanmook merged 1 commit into
mainfrom
refactor/drop-status-predicates
Oct 10, 2026
Merged

remcovanmook merged 1 commit into
mainfrom
refactor/drop-status-predicates

Conversation

@remcovanmook

Copy link
Copy Markdown
Owner

Since #145 the sync removes any row whose status isn't ok, migration 013 (released in v0.22.7) cleared the rest, and production confirms it: SELECT status, COUNT(*) FROM peeringdb_network_ixlan GROUP BY status → ok 66006. Every status predicate in the worker queries is therefore redundant.

Removed

  • api/query.js: the default status = 'ok' clause. An explicit ?status= still filters like any field: ok returns everything, anything else returns nothing.
  • api/depth.js: the predicates in child sets (depth 1 and 2), parent expansion and through-sets.
  • api/handlers/compare.js: all of them.
  • search/: keyword, graph-hydration and graph-search lookups. filterByMetadata now omits WHERE when no metadata predicate remains.

Why it's also faster

Child-id lookups become index-only. depth=1's SELECT id, <fk> FROM child WHERE <fk> IN (…) previously had to fetch each child row to check status. SQLite's plan changes from USING INDEX peeringdb_network_facility_net_id_idx to USING COVERING INDEX peeringdb_network_facility_net_id_idx. The same applies to every FK-based set lookup.

Tests

  • query.test.js: the default-status assertions now assert there is no status clause; the explicit ?status= case is kept.
  • upstream_compat_sqlite.test.js: removed fixtures that seeded a deleted link and a pending campus, a state D1 can no longer hold, and the expansion-level pending tests. The invariant is tested where it's enforced, in fix(sync): D1 holds only status='ok' rows #145's sync test.
  • Workers 1469/1469, integration 24/24, upstream patterns 60/60, typecheck clean, pre-push hook passed.

🤖 Generated with Claude Code

Since #145 the sync removes any row whose status isn't 'ok', migration
013 cleared the rest, and production confirms it (netixlan: 66,006 rows,
all 'ok'). Every status predicate was redundant: the default status='ok'
filter in the query builder, depth expansion and through-sets, compare,
and keyword/graph search. An explicit ?status= still filters like any
field (ok → everything, anything else → nothing).

Besides less SQL, child-id lookups become index-only: depth=1's
SELECT id, <fk> FROM child WHERE <fk> IN (…) now uses the FK index as a
COVERING INDEX instead of fetching each child row to check status.

Test fixtures that seeded deleted/pending rows (a state D1 can no longer
hold) are removed; the sync test from #145 covers the invariant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@remcovanmook
remcovanmook merged commit 7c26380 into main Oct 10, 2026
10 checks passed
@remcovanmook
remcovanmook deleted the refactor/drop-status-predicates branch October 10, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants