Repository navigation
Description
Problem
The URL tab under-reports whenever a source scope is selected.
Two changes that are each correct on their own combine badly:
- perf(citations): aggregate the overview in Postgres instead of downloading it #744 caps the URL list at the top 2,000 by citation count. The largest brand has 117,316 distinct URLs in its window — 25 MB of payload for a table that shows a hundred at a time — so the cap is what makes the page affordable.
- fix(citations): replace source filters with client-side scope #742 applies the source scope (All · Brand · Competitors · Third-party) on the client, over the rows that arrived. That is what removes the server round trip the scope used to cost.
The scope therefore filters within the global top 2,000. A brand whose competitors are cited rarely can select Competitors and see almost nothing, while competitor URLs exist in the data and would have appeared before the cap landed.
The Domains tab is unaffected — domains are returned uncapped, all 20,366 of them for that brand, so filtering them after the rollup is exact.
Nothing is wrong with either change. The cap arrived a day before the scope filter, and neither knows about the other.
Why it is quiet
The pager reports the filtered count, so the tab reads as complete: "12 of 12" rather than "12 of however many exist". A reader has no way to tell the difference between this brand has twelve competitor URLs and twelve of this brand's competitor URLs happened to rank in the global top two thousand.
Fix
Teach citations_urls about the scope so the cap applies inside it — the top 2,000 competitor URLs rather than the competitors among the top 2,000 URLs.
The obstacle is that a category is not a property the database knows. classifyDomain decides it from the brand's own domain list and its competitor list, both of which live in brand_domains and competitors. Two ways to close that:
- Pass the lists in. The function takes brand domains and competitor domains as arrays and classifies with a suffix match, mirroring
matchesSuffix. Keeps one definition of the rule in SQL and one in TypeScript, which will drift. - Resolve the scope to a domain list in the caller. The action already classifies every domain for the Domains tab — it can hand
citations_urlsthe domains that survive the scope and let the function filter ondomain = any(...). One definition of the rule, in TypeScript, and the function stays ignorant of what a competitor is.
The second is the better shape. The domain list can be large (20,366 for the largest brand), so it has to travel in the request body rather than the query string — the mistake #741 already paid for once.
Acceptance criteria
- Selecting a scope returns the top N URLs within that scope, not the scope's share of the top N overall.
- The reported total reflects the scope, so the tab never implies it is showing everything when it is not.
- The Domains tab is unchanged.
- No new definition of what counts as a brand or competitor domain — the existing one is reused.
Activity
fix(citations): count the Unique Domains KPI within the selected sour…