skip image optimization for tiny placeholder images
Images under 100 bytes (e.g. 44-byte 1x1 pixel webp stubs from seeded data) crash libvips. Filter them at three levels: VariantCache skips them in the query, Optimizer returns :too_small, and OptimizeWorker cancels (not retries) the job to avoid activity log spam. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ae6cf209aa
commit
a5ba90c5c9
@ -29,6 +29,7 @@ defmodule Berrypod.Images.OptimizeWorker do
|
||||
{:ok, _} -> :ok
|
||||
{:error, :not_found} -> {:cancel, :image_not_found}
|
||||
{:error, :no_data} -> {:cancel, :no_image_data}
|
||||
{:error, :too_small} -> {:cancel, :image_too_small}
|
||||
{:error, reason} -> {:error, reason}
|
||||
end
|
||||
end
|
||||
|
||||
@ -13,6 +13,8 @@ defmodule Berrypod.Images.Optimizer do
|
||||
@thumb_size 200
|
||||
@max_stored_width 2000
|
||||
@storage_quality 90
|
||||
# Skip images smaller than this — they're placeholders or corrupt
|
||||
@min_image_bytes 100
|
||||
|
||||
def cache_dir do
|
||||
Application.get_env(:berrypod, :image_cache_dir) ||
|
||||
@ -80,6 +82,9 @@ defmodule Berrypod.Images.Optimizer do
|
||||
Repo.update!(ImageSchema.changeset(image, %{variants_status: "complete"}))
|
||||
{:ok, :svg_skipped}
|
||||
|
||||
%{data: data} when byte_size(data) < @min_image_bytes ->
|
||||
{:error, :too_small}
|
||||
|
||||
%{data: data, source_width: width} = image ->
|
||||
File.mkdir_p!(cache_dir())
|
||||
|
||||
|
||||
@ -52,10 +52,12 @@ defmodule Berrypod.Images.VariantCache do
|
||||
|
||||
defp ensure_database_image_variants do
|
||||
# Only load IDs and source_width for the disk check — avoids loading BLOBs
|
||||
# Skip tiny images (< 100 bytes) — they're placeholders that can't be processed
|
||||
incomplete_ids =
|
||||
ImageSchema
|
||||
|> where([i], i.variants_status != "complete" or is_nil(i.variants_status))
|
||||
|> where([i], i.is_svg == false)
|
||||
|> where([i], i.file_size >= 100)
|
||||
|> select([i], {i.id, i.source_width})
|
||||
|> Repo.all()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user