mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 02:45:39 -04:00
Optimize database queries: add indexes, batch cron scans, transactional writes
Add covering indexes for recommendation rank ordering, title staleness scans, and type+status filtering. Replace N+1 per-row staleness checks in cron jobs with set-based batch queries. Wrap availability refresh in a transaction for atomicity. Batch episode stills query and use existence check instead of loading all rows for count. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -124,6 +124,12 @@ export const titles = sqliteTable(
|
||||
uniqueIndex("titles_tmdbId_unique").on(table.tmdbId),
|
||||
index("titles_type_releaseDate").on(table.type, table.releaseDate),
|
||||
index("titles_type_firstAirDate").on(table.type, table.firstAirDate),
|
||||
index("titles_lastFetchedAt").on(table.lastFetchedAt),
|
||||
index("titles_type_status_lastFetchedAt").on(
|
||||
table.type,
|
||||
table.status,
|
||||
table.lastFetchedAt,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -316,6 +322,7 @@ export const titleRecommendations = sqliteTable(
|
||||
table.recommendedTitleId,
|
||||
table.source,
|
||||
),
|
||||
index("titleRecommendations_titleId_rank").on(table.titleId, table.rank),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user