From 8a5b337a5328e64dc46ca9cddd433091647d8384 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 26 May 2026 01:20:04 -0400 Subject: [PATCH] =?UTF-8?q?feat(fc-cleanup):=20min-dimension=20service=20f?= =?UTF-8?q?unctions=20+=20tests=20=E2=80=94=20Co-Authored-By:=20Claude=20O?= =?UTF-8?q?pus=204.7=20(1M=20context)=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/cleanup_service.py | 44 ++++++++++++++ tests/test_cleanup_service_audit.py | 76 +++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 tests/test_cleanup_service_audit.py diff --git a/backend/app/services/cleanup_service.py b/backend/app/services/cleanup_service.py index 3f749ad..99d2a6f 100644 --- a/backend/app/services/cleanup_service.py +++ b/backend/app/services/cleanup_service.py @@ -365,3 +365,47 @@ def prune_unused_tags(session: Session, *, dry_run: bool = False) -> dict: ) session.commit() return {"deleted": len(ids), "sample_names": sample} + + +# --------------------------------------------------------------------------- +# FC-Cleanup additions (2026-05-26): retroactive audit of import-filter rules. +# --------------------------------------------------------------------------- + +_MIN_DIM_SAMPLE_CAP = 50 + + +def project_min_dimension_violations( + session: Session, *, min_width: int, min_height: int, +) -> dict: + """Return {count, sample_ids} for image_record rows with width or + height below the thresholds. Synchronous SQL — no PIL inspection + needed since width/height are stored columns.""" + base = select(ImageRecord.id).where( + (ImageRecord.width < min_width) | (ImageRecord.height < min_height) + ) + count = session.execute( + select(func.count()).select_from(base.subquery()) + ).scalar_one() + sample_ids = session.execute( + base.order_by(ImageRecord.id).limit(_MIN_DIM_SAMPLE_CAP) + ).scalars().all() + return {"count": count, "sample_ids": list(sample_ids)} + + +def delete_min_dimension_violations( + session: Session, *, min_width: int, min_height: int, images_root: Path, +) -> int: + """Delete every image_record where width