Skip to content

perf(citations): rebuild citation rollups shortly after a topic move, not at the nightly sweep #1001

Closed

Description

@gkhngyk

Problem

The Citations daily rollups (00118) store topic_id in their rows. When a prompt moves to another topic, or is deleted, the trigger on prompts adds the brand to citation_rollup_rebuilds. The queue is only processed by rebuildQueuedCitationRollups() at the end of the nightly sweep (sweepInsightsRollups()).

Until then, the Citations page's topic filter shows the moved prompt's citations under its old topic. Depending on when the move happens, that lasts up to a day. A user who reorganizes topics and checks the result right away sees no change.

Proposal

Process the queue shortly after a change instead of waiting for the nightly sweep:

  • Schedule rebuildQueuedCitationRollups() on its own, every few minutes, next to the existing node-cron schedules in server/src/server.js. When the queue is empty the run is a single select.
  • Keep the call at the end of the nightly sweep as a fallback.
  • Don't let two runs overlap. A full-history rebuild of a large brand takes a few minutes (14-day chunks of ~12s each).

Bulk edits need nothing new: a brand re-queued while it is being rebuilt keeps its queue entry, because the entry is cleared only when requested_at has not moved.

Acceptance criteria

  • After a prompt moves topic, the Citations topic filter reflects it within the schedule interval plus the rebuild time.
  • Runs never overlap.
  • An empty queue costs one query per run.
  • Tests cover the schedule's overlap guard.

Activity

  1. added
    enhancement
    help wanted
    citations
    on Oct 11, 2026
  2. added a commit that references this issue on Oct 13, 2026
    7c369f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    citationsenhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions