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

@@ -7,7 +7,7 @@ defmodule BerrypodWeb.Admin.ProductShow do
@impl true
def mount(%{"id" => id}, _session, socket) do
case Products.get_product(id, preload: [:provider_connection, images: :image, variants: []]) do
case Products.get_product_with_preloads(id) do
nil ->
socket =
socket

View File

@@ -64,7 +64,7 @@ defmodule BerrypodWeb.Admin.Products do
@impl true
def handle_event("toggle_visibility", %{"id" => id}, socket) do
product =
Products.get_product(id, preload: [:provider_connection, images: :image, variants: []])
Products.get_product_with_preloads(id)
case Products.toggle_visibility(product) do
{:ok, updated} ->