Repository navigation
perf(search): sweep in-memory search sessions at most once a minute - #3895
Conversation
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]>
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
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. View limit details
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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
searchSessionStorerecords 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.getstill 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
nowfunction so the test can advance time without sleeping.Validation
go test ./internal/catalog/...(also with-racefor the store test): pass.make lint-changed: 0 issues.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
getchecks expiry on every read.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Throttle in-memory search-session sweeps to once per minute
searchSessionSweepIntervaland a configurable clock tosearchSessionStorein 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.pruneExpiredSearchSessionsas a reusable helper and switches in-memory expiry checks to the store clock. The Redis-backed expiry check still uses the system clock.putMemorysweep logic if any consumer assumed immediate cross-account eviction.Macroscope summarized ec300ee.