Skip to content

perf(search): sweep in-memory search sessions at most once a minute - #3895

Merged
Quick104 merged 1 commit into
mainfrom
perf/throttle-search-session-sweep
Nov 9, 2026
Merged

Quick104 merged 1 commit into
mainfrom
perf/throttle-search-session-sweep

Conversation

@Quick104

@Quick104 Quick104 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

On a server running Meilisearch without Redis, each new search scanned the paging sessions of every account and dropped the expired ones. It held the store's mutex the whole time, so continuation requests ("load more") for other accounts waited behind it. A single household won't notice. On a server with many accounts, every search costs time in proportion to the total number of stored sessions. This is a follow-up to #3699, where CodeRabbit flagged the same cost.

This change runs the cross-account sweep at most once a minute. The rest of each write is unchanged.

Approach

The in-memory searchSessionStore records when it last swept. A write runs the full sweep only when a minute has passed since the last one. Without the sweep, sessions from accounts that stop searching would stay in memory until restart, so the sweep is throttled, not removed. Every write still drops its own account's expired sessions and evicts the session with the earliest expiry once the account holds 16. The per-account limit therefore holds regardless of when the sweep last ran. get still rejects and deletes expired sessions.

The Redis path, the 15-minute TTL, the per-account limit, and API behavior are unchanged. The store gets an optional now function so the test can advance time without sleeping.

Validation

  • go test ./internal/catalog/... (also with -race for the store test): pass.
  • make lint-changed: 0 issues.
  • The extended in-memory store test checks three things: an idle account's expired sessions survive writes within the interval, a write drops its own account's expired sessions, and the next write after the interval removes the idle account. I checked that it catches regressions: it fails with the interval set to zero (the old sweep on every write), and it fails with the per-account prune removed.

Evidence

Evidence: none, no user-visible change

Risks

An idle account's expired sessions can stay in memory up to a minute longer than before. They were never served after expiry, because get checks expiry on every read.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code shell and file tools, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: gpt-6.1-sol (Codex) reviewed ec300ee for throttle boundaries, locking, per-account limits, idle-account memory growth, Redis-path changes, and test determinism; no findings.

🤖 Generated with Claude Code

Note

Throttle in-memory search-session sweeps to once per minute

  • Adds searchSessionSweepInterval and a configurable clock to searchSessionStore in search_session.go. In-memory writes now prune expired sessions for the writing account on every write, but sweep other accounts only when the interval has elapsed. Empty account entries are removed after cross-account sweeps.
  • Extracts pruneExpiredSearchSessions as a reusable helper and switches in-memory expiry checks to the store clock. The Redis-backed expiry check still uses the system clock.
  • Tests in search_session_test.go use a controllable clock to verify per-account pruning, interval isolation, and cross-account sweep timing.
  • Risk: expired sessions in idle accounts can now persist up to one minute longer than before; check putMemory sweep logic if any consumer assumed immediate cross-account eviction.

Macroscope summarized ec300ee.

Without Redis, every new Meilisearch search walked every account's paging
sessions to drop expired ones, holding the mutex that continuation reads
take. Run that cross-account sweep at most once a minute. Each write still
drops its own account's expired sessions and enforces the 16-session limit,
so the per-account bound doesn't depend on the sweep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 9, 2026
@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1d48eb77-ddba-4a81-b539-af191a9a0f61
Commits

Reviewing files that changed from the base of the PR and between 84dbfe1 and ec300ee.

Files selected for processing: 2

  • internal/catalog/search_session.go
  • internal/catalog/search_session_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T17:23:57.456088Z ec300ee PR opened
🔒 Security Review ✅ Completed 2026-11-09T17:25:53.849807Z ec300ee PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-triage silo-triage Bot added go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish triaged High-confidence review completed; does not mean fixed, validated, or accepted for release. labels Nov 9, 2026
@Quick104
Quick104 merged commit 5f6223e into main Nov 9, 2026
26 of 28 checks passed
@Quick104
Quick104 deleted the perf/throttle-search-session-sweep branch November 9, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority. triaged High-confidence review completed; does not mean fixed, validated, or accepted for release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant