Repository navigation
perf(registry): cut skilld-db rows read on repo skill counts - #212
Merged
Merged
Conversation
skilld-db reads grew from 104M to about 1B rows a day, pushing the account past the 25B/month D1 free tier. The hot statements computed a correlated repo Skill count per row before any LIMIT, reading sum(c^2) rows, and re-ran on one to five minute caches. repos.repo_skill_count is not used: sync stores the SKILL.md file count and never updates it when source_resolved clears, and it disagrees with the live count for 7,159 of 8,618 repos. Claude-Session: https://claude.ai/code/session_014N85FDJLggfBs3BHJXT7GZ
PRs #189 and #190 already change the tag and cluster handler cache options, so this branch keeps only the query changes there. Claude-Session: https://claude.ai/code/session_014N85FDJLggfBs3BHJXT7GZ
Collaborator
Author
|
Checked by hand against prod skilld-db, since CI cannot cover it:
|
Contributor
🤖 MERGED
GitHub merged this pull request. No material findings were recorded. The pull request closed. |
This was referenced Sep 14, 2026
1 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
Related to #182, #185, #186
❓ Type of change
📚 Description
skilld-db reads went from 104M rows/day on 11 Aug to about 1B/day. That puts the account past the 25B/month D1 free read tier. Three statements did most of it between 11 and 13 Sep:
listDuplicateCandidateRowsjson_eachThe shared cause is
(SELECT COUNT(*) FROM skills WHERE owner/repo ...)in a select list, evaluated for every matching row before anyLIMIT. That reads sum(c²) rows, anddavila7/claude-code-templatesalone has 875 Skills. The count is now read once per statement through a grouped join, or only for rows on the page. The duplicate candidate and sitemap caches go from 5 minutes to 1h plus a day of stale-while-revalidate. The derived tag counts come from one grouped scan per hour, because a 404 for an unknown slug was never cached and re-ran the scan on every request.I first planned to read
repos.repo_skill_countinstead, but it is a different number. Sync stores the SKILL.md file count, and the paths that clearsource_resolvednever update it. On prod it disagrees with the live count for 7,159 of 8,618 repos, including 299 that do have resolved Skills. Swapping it in would changecanonicalRepoSkillPathrouting, so the exact count stays.Rows read per call on prod skilld-db, before and after:
users/davila7/skillstesting, count + listquerySkillsone per ownertestingLoose ends:
maxAgeand swr changes are left to fix(clusters): add stale-while-revalidate window to cluster caches #189 and fix(registry): serve tag profiles stale-while-revalidate #190, which already touch those lines. The cost plan wanted 15 minutes or more on both. fix(clusters): add stale-while-revalidate window to cluster caches #189 currently has 60s fresh plus 5 min stale, which may be worth raising there.querySkillsnow sort the page again by the same key. On the name and owner sorts, rows that tie on that key could come back in a different order.community.tsalso has the correlated count, but moving it saved nothing (344K to 343K), so its cost is elsewhere. The collection detailranked_skillsCTE (120M over 71 calls) is also out of scope.https://claude.ai/code/session_014N85FDJLggfBs3BHJXT7GZ