Add database optimizations for photo search and pagination
Implement database-level sorting with composite indexes for efficient date and tag queries. Add pagination metadata support and optimize tag count queries using batch processing.
This commit is contained in:
15
migrations/2026-01-18-000000_optimize_photo_search/up.sql
Normal file
15
migrations/2026-01-18-000000_optimize_photo_search/up.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- Add composite indexes for search performance optimization
|
||||
-- This migration addresses N+1 query issues and enables database-level sorting
|
||||
|
||||
-- Covering index for date-sorted queries (supports ORDER BY + pagination)
|
||||
-- Enables efficient date-based sorting without loading all files into memory
|
||||
CREATE INDEX IF NOT EXISTS idx_image_exif_date_path
|
||||
ON image_exif(date_taken DESC, file_path);
|
||||
|
||||
-- Optimize batch tag count queries with GROUP BY
|
||||
-- Reduces N individual queries to a single batch query
|
||||
CREATE INDEX IF NOT EXISTS idx_tagged_photo_count
|
||||
ON tagged_photo(photo_name, tag_id);
|
||||
|
||||
-- Update query planner statistics to optimize query execution
|
||||
ANALYZE;
|
||||
Reference in New Issue
Block a user