Skip to content

[bug] First bulk unmark of a large show can spend seconds rescanning watch history #2997

Closed

Description

@Quick104

What happened

The first bulk unmark of a 5,000-episode show took 24.96 seconds in a Silo dev deployment. The request succeeded and all episodes became unwatched. Two later attempts took 0.54 and 0.45 seconds. Marking the show watched took 0.33–1.00 seconds; marking or unmarking one episode took about 12 ms.

A separate database probe reproduced the slow history-delete plan in 20.82 seconds. This appears when the hidden-history table was empty when statistics were collected, then receives thousands of watermarks within the unmark transaction.

Steps to reproduce

  1. In a disposable deployment, seed ten synthetic shows with 5,000 episodes each and completed history for half the episodes under one profile.
  2. Start with no hidden-history watermarks for those episodes and collect database statistics.
  3. Mark one show watched using POST /api/v2/watched/{series_id}.
  4. Time DELETE /api/v2/watched/{series_id} and verify all 5,000 episodes become unwatched.
  5. Compare with later mark/unmark attempts after statistics have caught up.

The standalone probe inserts 5,000 watermarks in a transaction, runs EXPLAIN (ANALYZE, BUFFERS) on the exact history-delete statement, then rolls back.

Expected behavior

Bulk unmark should avoid repeatedly scanning the profile's history when thousands of watermarks are newly inserted. A newly used history-removal table should not make this operation tens of seconds slower than subsequent attempts.

Silo version / commit

d7cb0d142, based on 5ec820486. The relevant internal/userstore/pgstore/progress.go code is unchanged from the base. The slow DELETE does not contain a show-title filter.

Deployment

Docker Compose, isolated dev deployment, PostgreSQL 18.

Clients affected

Native v2 API; verified through an authenticated Chromium session. A saved unwatched collection reflected the correct result after the request completed.

Relevant logs

No logs available. Request measurements and database execution-plan evidence are described below.

Technical notes

PostgresUserStore.removeHistoryItems first inserts hidden-history watermarks, then deletes matching history rows at internal/userstore/pgstore/progress.go:1590.

With cold statistics, the plan estimates one row in user_history_hidden_items, but reads 5,000. It chooses a nested loop with 5,000 scans of idx_user_watch_history_watched_at; each scan filters out 27,499 rows on average. Execution takes 20,819 ms and hits approximately 3.1 million shared buffers. No trigger time appears in this plan.

The query should remain efficient when the watermark insert materially changes the table within the same transaction. The fix has not been chosen or verified. This is distinct from #646 / #647, which addressed notification-decorator fan-out rather than this history-delete query plan.

AI disclosure

  • Harness: Codex in T3 Code
  • Tools: Codex, authenticated browser capture, PostgreSQL execution plans
  • Model: gpt-6.1-sol
  • Involvement: AI-assisted, not yet human verified
  • Independent review: none for this separate performance finding

Confirmations

  • Searched open and closed issues and pull requests; the older large-series issue addressed a different cause.
  • Reproduced on a real isolated deployment and independently with the database statement.
  • No raw logs are represented as available.

Source: found in review of #2996.

Activity

  1. added
    bug
    on Oct 24, 2026
  2. added
    impact: perf
    priority: P2
    on Oct 24, 2026
  3. added a commit that references this issue on Nov 14, 2026
    f5ef81b
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

    bugimpact: perfpriority: P2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions