perf: search index rebuild is not atomic and drops tables on concurrent requests
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 12h 29m
- Merged PRs (30d)
- 12
Description
Problem
src/server/api/search.ts drops and recreates FTS tables in buildIndex() on each version init. If two requests hit the search endpoint simultaneously during index build, the second request can fail because the tables were just dropped.
The lock file mechanism (/tmp/chronicle-search-ready) is also unreliable across processes and deployments since temp files get cleaned.
Suggested Fix
- Build the new index in temporary tables, then atomically swap (rename) them
- Replace the lock file with an in-memory ready flag (already have
indexedVersionsset — lean on that) - Add a mutex/promise guard so concurrent
ensureIndex()calls wait for the first build to complete (partially done viaindexPromisebut the drop/recreate pattern still races)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/server/api/search.ts, reading buildIndex() and ensureIndex(), then trace indexedVersions and indexPromise. Replace the drop-and-recreate flow with temporary-table swapping, remove reliance on /tmp/chronicle-search-ready, and ensure concurrent builds wait for one completed build. Done means concurrent search requests no longer fail during index construction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, databases, search
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100