perf(server): High-performance backend optimizations - #7
Merged
Conversation
…ization, and contact hydration - Propagated AbortSignal from Express `/api/search/semantic` connection close to AI service & provider adapters to prevent token and compute leaks. - Replaced loop-nested N+1 queries in `normalizeContacts` with pre-fetched bulk tags/interests lookup Maps, reducing latency by ~150x. - Refactored `hydrateMany` to chunk queries at 500 parameters (respecting SQLite limit) and use O(N) map-joins with exact single-record schema parity. - Added dynamic microsecond-range sequential hydration fallback for collections <= 3 contacts. - Verified zero regression with full Vitest integration suite (180 tests passing).
arvarik
added a commit
that referenced
this pull request
Aug 4, 2026
…ication Data lifecycle (rec #7): - Deletes are now soft: contacts move to a trash (deletedAt + isArchived) with restore via POST /api/trash/:id/restore, an Undo toast in the UI, immediate purge via DELETE /api/trash/:id, and automatic hard-deletion after TRASH_RETENTION_DAYS (default 30, daily sweep). FTS triggers are trash-aware so trashed contacts vanish from search and reindex on restore. - Automatic SQLite snapshots via the online backup API into DATA_DIR/backups with rotation (BACKUP_INTERVAL_HOURS / BACKUP_KEEP), plus GET/POST /api/backups. - Full export: GET /api/export/json (entire database, downloadable) and GET /api/export/csv (flat contacts spreadsheet, RFC-4180 escaping). Authentication (rec #1): - Single-user bearer token gating /api and /uploads, enforced when AUTH_TOKEN is set or AUTH_REQUIRED=true (token auto-generated, persisted to DATA_DIR/auth-token, printed in logs at boot). Timing-safe comparison. - /api/auth status/login/logout; login sets an HttpOnly SameSite=Strict cookie for the SPA (AuthGate sign-in screen); scripts and MCP clients use Authorization: Bearer. - Docker is secure by default (AUTH_REQUIRED=true in the image); dev server warns when bound beyond localhost without auth. Remote-access guidance documented (Tailscale / TLS reverse proxy). Testing: 316 tests (22 new integration tests covering trash/restore/purge, backup files on disk, export contents, and the full auth matrix), verified end-to-end in Docker on OrbStack including token persistence across restarts. Docs and .env.example updated; validation schema gap (cadenceDays/website) closed by the new tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Accomplishments
This Pull Request implements the approved backend architectural optimizations for
contrackto eliminate critical N+1 database bottlenecks and enhance client request resiliency.1. Connection Abort Propagation (Security & Cost Control)
AbortControllerto Expressreq.on("close")in/api/search/semantic.2. O(1) Batch Normalization (Dedupe Performance)
normalizeContactsto batch-load tags and interests at start, mapping them via in-memory O(1) lookups.3. High-Performance Contact Bulk Hydration
hydrateManyincontactRepository.tsto leverage query-parameter safe chunked SQL queries (chunk size of 500) and O(N) map-joins.contactIdfields from child records to guarantee 100% downstream API payload shape parity.4. Validation