Files
outline/server/migrations
Tom MoorandClaude Opus 4.8 b2bf82d78b Add composite (userId, createdAt) index for searches.list (#12767)
* Add composite (userId, createdAt) index for searches.list

The searches.list endpoint filters by userId/teamId and orders by
createdAt DESC, but search_queries only had single-column indexes. Since
a row is inserted on every search, the table grows large and the planner
must either fetch and sort a user's entire search history or scan the
createdAt index until enough matching rows are found — both proportional
to history size rather than page size.

Add a composite index on (userId, createdAt) so the query can seek
directly to the user's rows in createdAt order and stop after LIMIT rows.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013wAHcneY9eV4fZtCBq8Ue3

* Drop redundant userId and unused createdAt indexes on search_queries

With the new (userId, createdAt) composite index in place, the
single-column userId index is fully redundant (covered as a leftmost
prefix) and the createdAt index is unused — no query orders or filters
by createdAt without also constraining userId. Dropping both removes
index-maintenance overhead on the high-write search_queries table. The
teamId index is kept for the team permanent deleter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013wAHcneY9eV4fZtCBq8Ue3

* Use CONCURRENTLY for search_queries index changes to avoid table locks

Switch the composite index creation and the redundant index drops to raw
CREATE/DROP INDEX CONCURRENTLY IF [NOT] EXISTS so the migration takes no
blocking lock on the high-traffic search_queries table. The migration
runner (Umzug) does not wrap migrations in a transaction, so CONCURRENTLY
is safe here.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013wAHcneY9eV4fZtCBq8Ue3

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-21 08:01:56 -04:00
..