Skip to content

fix(citations): replace source filters with client-side scope - #742

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
BharadwajKanneveti:fix/citations-source-scope
Aug 20, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
BharadwajKanneveti:fix/citations-source-scope

Conversation

@BharadwajKanneveti

Copy link
Copy Markdown
Contributor

Summary

  • Replaced the three mutually-exclusive citation source toggles with a single Sources selector:
    • All
    • Brand
    • Competitors
    • Third-party
  • Added sourceScope to the UI filter state and removed the old excludeOwnDomain, competitorOnly, and ownOnly fields and wiring.
  • Moved source-scope filtering to the client using the existing citation category values, avoiding a backend re-scan when the source scope changes.
  • Applied source-scope filtering to both domain and URL tables.
  • Updated pagination and CSV exports to use the filtered domain and URL rows.
  • Kept KPI totals based on the overall citation window rather than the selected source scope.
  • Preserved the distinction between Third-party and Competitors: third-party includes the six non-brand, non-competitor categories.

Related issue

Closes #655
Closes #657

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

Checklist

@BharadwajKanneveti BharadwajKanneveti changed the title fix(web): replace source filters with client-side scope fix(citations): replace source filters with client-side scope Aug 19, 2026
@BharadwajKanneveti

Copy link
Copy Markdown
Contributor Author

@gkhngyk I have made a draft pr as you asked please check and let me know if you find any issues.

@BharadwajKanneveti
BharadwajKanneveti marked this pull request as ready for review August 20, 2026 08:38
@gkhngyk
gkhngyk merged commit 7664375 into ansvisor:main Aug 20, 2026
4 checks passed

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

gkhngyk added a commit that referenced this pull request Aug 20, 2026
… 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.
gkhngyk added a commit that referenced this pull request Aug 27, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants