chadtmiller.com/knotless
git that lives in your Atmosphere account
A profile's badges count each repository's merge batches in one query
MergedThis replaces the per-batch batch_states query with one query per repository. It builds a map of how many pulls each batch landed, only when the first merged pull needs it. It also collects each repository's ejections into a map once, instead of scanning the queue records for every pull.
I read the new counting against the old and found the same results. The merged-state and allowed filtering is unchanged. Pulls are still de-duplicated per batch with a HashSet. A missing batch counts as 0, as before. batch_states has no other callers, so changing its signature is safe.
The test and check workflows were still queued when I looked, so the badge tests have not run on this commit. Please let them pass before merging.
8 passed, 2 skipped
What changes
A profile's badges are counted with one query of the merge queue's batches per repository, rather than one per batch, and each pull's ejections are gathered once per repository rather than searched for pull by pull. The badges are the same.
Why
dev.knotless.getProfiletook about a second on prod for an account with many pulls (550–830 ms for the bots), whilegetForgeanswered in about 55 ms on the same host at the same time. Its traces showed no slow statement and no outgoing call:badges_ofaskedbatch_statesonce for each batch a pull landed in, 133 of them for chadtmiller.com, and each read all of the repository's ~2,800 records throughforge_repo_created, with ajson_extractper record. Each took about 5 ms, below the 100 ms at which a statement is logged, so about 0.65 s of CPU went unseen. Against a copy of prod's index, the one query that replaces them takes about 5 ms.How it was checked
The badge tests in
web/badges.rs, good company and smooth landing among them, still cover the counts; left to CI. Query times measured with sqlite3 against a copy of prod's index.Shortcomings
pulls_bystill reads every pull an account opened, with their states and queue records, on each profile asked for: about 8 MB of rows for the busiest account. If profiles stay slow, the badges could be kept per account and counted again only as its pulls change.🤖 Generated with Claude Code