Repository navigation
Description
Problem
The Citations page's Domains and URLs tabs read daily rollups since 00118, but the Gaps tab still runs two raw scans per load:
citation_gap_domainscitation_competitor_sources
Both scan every answer in the window, every citation of those answers, and unpack competitor_mentions. On the largest brand they take about 2s. Before 00118 the domain table showed the same cost growing with citations: it reached 11.8s.
The existing rollups can't answer these reads, because the measures are per answer:
- Present answers: answers where the brand is present, meaning it is mentioned, or one of its domains (
p_brand_domains) is cited in the same answer. - Competitor-present answers: answers where a competitor is mentioned.
- Domain weight: each answer weights its cited domains
1 / number of distinct domains it cites. - Competitor names per domain: the competitors mentioned in the answers behind that domain.
Proposal
Add gap rollups at the same grain as citation_domain_daily (day, model_used, platform, region, topic_id), written by refresh_citations_daily:
- Per domain:
- gap answers: competitor present, brand not present;
- gap strength: sum of the weight over those answers;
- present answers, for
appears_in_ours.
- Per (domain, competitor):
- answers feeding the domain, and their strength, for
citation_competitor_sources; - the same counts restricted to gap answers, for
competitor_names.
- answers feeding the domain, and their strength, for
- Per day: present answers next to
answersincitation_result_daily, forour_answer_count.
Add *_daily read variants that take the same filters as citations_domains_daily. Keep these steps at read time:
- domain tagging against
p_brand_domainsandp_competitor_domains, so excluded domains stay a filter; - competitor names, taken from the live
competitorstable with the current name fallback.
Use the security definer + explicit org check pattern from 00119. citation_urls has no select policy for authenticated.
Brand domains are baked in
Whether the brand counts as present depends on the brand's own domains when the rollup is written. A change to brand_domains must therefore queue a rebuild through citation_rollup_rebuilds, the same way a topic move does. #1001 makes that queue run shortly after a change.
Prompt-filtered reads stay on the raw functions, as they do for the other Citations tabs.
Acceptance criteria
- The Gaps tab reads the daily functions for every preset except a prompt filter.
- Results match the raw functions for whole-day windows on at least three brands, including the largest.
- Adding or removing a brand domain queues a rebuild.
- Verified under the
authenticatedrole as an org member (rows) and as a member of another org (no rows). - Backfill script, as for 00118.
Activity
knockknock10 commentedon Oct 18, 2026
hey @gkhngyk I would love to work on again !!
If available could you please assign these to me?
gkhngyk commentedon Oct 18, 2026
Thanks @knockknock10. This one stays with us for now: it rewrites
refresh_citations_daily, which #1131 is changing at the same time. How is #918 going? A first PR for one tool group would be welcome.knockknock10 commentedon Oct 18, 2026
Hey @gkhngyk Sorry, I completely forgot to follow up on #918 because of my exams. I've now completed the work and will get the first PR for one tool group submitted. Thanks for the clarification and patience!
perf(citations): serve the Gaps tab from daily rollups (ansvisor#1257)