Repository navigation
fix(citations): replace source filters with client-side scope - #742
Conversation
|
@gkhngyk I have made a draft pr as you asked please check and let me know if you find any issues. |
gkhngyk
left a comment
There was a problem hiding this comment.
Thanks — this matches the design decision exactly: a strict partition, with third-party meaning neither brand nor competitor rather than everything-except-mine. Moving the scope client-side removes the re-scan #657 was about, and pagination and the CSV export both follow the filtered rows rather than the raw ones.
One interaction to flag, and it is mine, not yours: #744 landed yesterday and caps the URL list at the top 2,000 by citation count. Your filter applies within that set, so scoping to Competitors can under-report URLs whose competitors sit below the cap. Domains are unaffected — those are returned uncapped. Fixing it means teaching the URL function about scope so the cap applies inside it, which is a separate change; I'll open an issue and take it.
Nothing to change here.
… the table it scopes (#748) The own/competitor/third-party filter was a dropdown at the end of the page's filter bar, which misplaced it twice over. It was the only control there with no label. Every other filter — Topic, Prompt, Platform, Region — names itself above the input; this one leaned on a "Sources" placeholder that its own default value ("All") covered up, so the bar ended in a box reading "All" with nothing on screen saying all of what. It also carried none of the sizing the others share, so it rendered taller and in a larger type than its neighbours. And it does not scope the page. The KPIs count every citation whatever it says, and Competitor Gaps and Source Types ignore it outright — it narrows the Domains and URLs tables and nothing else. Sitting among the page-wide filters it claimed a reach it never had. It now renders as a segmented control inside the Top Sources card, above the two tabs it applies to and hidden on the two it does not, shaped like the date-range control so the two read as the same kind of choice. Also drops the `showCategoryToggles` prop, which existed only to hide this dropdown on the single-URL page, and the unused Button import left behind by #742.
…it (#791) The URL tab under-reported whenever a source scope was selected. Two changes that are each right on their own combined badly: #744 caps the list at the top 2,000 by citation count, and #742 then applied the scope on the client, over the rows that arrived. So the scope filtered within the global top 2,000. Measured on the largest brand, a 30-day window: scope shown actually exist Brand 21 395 Competitors 125 2,794 And it was silent — the pager counts what it filtered, so the tab read "125 of 125". A reader could not tell "this brand has 125 competitor URLs" from "125 of them ranked in the global top two thousand". citations_urls now takes the domains a scope resolves to and cuts the set before the limit; total_urls counts the scoped set, so the tab reports the scope rather than the cap. The three scopes now partition the window exactly: 395 + 2,794 + 94,131 = 97,320. What a brand or competitor domain *is* stays in TypeScript. The caller already runs classifyDomain over every aggregated domain to build the Domains tab, and the resolver reads that result, so the rule keeps one definition instead of gaining a second one in SQL. Two parameters rather than one, departing from the issue's sketch: resolving every scope to an include list would send 17,532 domains for Third-party — the whole cited set minus fourteen. Naming the fourteen to exclude says the same thing in a request that fits in a packet. The filter sits after the aggregate, and that placement is load-bearing. Pushed into the citation scan the planner abandons the hash join for a nested loop: 4.57s against a 1.67s unscoped baseline, close to the 8s statement timeout on a warm cache. Applied to the aggregated rows it is a hash semi-join costing 11ms, and every scope lands within noise of the unscoped query. Selecting a scope now refetches the overview, since the scope has to be known before the query runs. The unscoped view every page open starts on keeps its three queries in flight, so the default load is unchanged. The Domains tab is untouched: domains come back uncapped, so filtering them client-side is exact.
Summary
Sourcesselector:sourceScopeto the UI filter state and removed the oldexcludeOwnDomain,competitorOnly, andownOnlyfields and wiring.categoryvalues, avoiding a backend re-scan when the source scope changes.Third-partyandCompetitors: third-party includes the six non-brand, non-competitor categories.Related issue
Closes #655
Closes #657
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsChecklist
feature/,fix/,chore/,docs/) — see https://github.com/ansvisor/ansvisor/blob/main/CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)