optimise product queries: skip image blobs, limit listing preloads, add composite index
All checks were successful
deploy / deploy (push) Successful in 1m29s

The listing preload (images: :image) was loading the full images table row
including the data BLOB column (~3MB per page). Now only loads :id and
:source_width. Listing preloads also limited to first 2 images (primary +
hover) since product cards don't use the rest. Added composite indexes on
(visible, status, inserted_at) and (visible, status, category) to eliminate
the TEMP B-TREE sort SQLite was doing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-03-02 17:29:15 +00:00
parent 297f3de60f
commit 2f3b7e7b21
6 changed files with 79 additions and 22 deletions

View File

@@ -0,0 +1,14 @@
defmodule Berrypod.Repo.Migrations.AddProductsListingIndexes do
use Ecto.Migration
def change do
# Composite covering index for the main listing query:
# WHERE visible = 1 AND status = 'active' ORDER BY inserted_at DESC
# Replaces the individual visible + status indexes for this pattern
# and eliminates the TEMP B-TREE sort SQLite was doing.
create index(:products, [:visible, :status, :inserted_at])
# Filtered listing by category (second most common query pattern)
create index(:products, [:visible, :status, :category])
end
end