Migration 0039: harden non-comic cleanup, reorder ACL index, drop dead FTS dedupe#693
Merged
ajslater merged 1 commit intov1.11-performancefrom May 2, 2026
Merged
Conversation
…d FTS dedupe Three review-driven cleanups to the 0039 migration so it's safer and faster on real-world installs: - ``_remove_non_comic_comics`` now refuses to delete unless it can stat-probe at least one comic-suffix path successfully, and the deletable queryset is restricted to ``page_count == 0`` rows (the phantom-row signature from the original importer bug). Together these mean a misconfigured Docker volume can no longer turn the cleanup into a mass-delete: a real comic with an unusual name has ``page_count >= 1`` and is never a candidate, and an unmounted filesystem trips the sentinel and skips the step entirely. - The composite ACL index ``codex_comic_lib_ari_idx`` is now built *after* ``_backfill_age_rating_metron_index`` so SQLite does one sorted index build instead of incrementally maintaining the index during the bulk UPDATE. - The FTS dedupe ``RunSQL`` (and its ``_FTS_DEDUPE_SQL`` constant) has been removed — it ran immediately before ``DROP TABLE codex_comicfts``, so it was dead code on this path. Also swap the ``print()`` calls in the cleanup function for the ``loguru.logger`` already imported at the top of the file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three review-driven cleanups to migration
0039_metron_age_rating_default_view_and_performance.py— no functional changes outside the migration, just safety and efficiency improvements to make it harder to fail or misbehave on real installs.Hardened
_remove_non_comic_comicswith two independent defenses against an unmounted comics volume turning the cleanup into a mass-delete:_comics_fs_reachable()helper probes up to 10 known comic-suffix paths viaPath.is_file(). If none stat as files, the cleanup logs a warning and skips entirely.page_count == 0predicate — the deletable queryset is now restricted to phantom-row signature only (the original importer bug always leftpage_count = 0). A real comic with an unusual filename has at least one page and is never a candidate.Reordered the composite ACL index
codex_comic_lib_ari_idxto be built after_backfill_age_rating_metron_indexso SQLite does one sorted index build instead of incrementally maintaining the index during the bulk UPDATE oncodex_comic.Removed the FTS dedupe
RunSQL(and the_FTS_DEDUPE_SQLconstant). It ran immediately beforeDROP TABLE codex_comicfts, so it was dead code — pure overhead and one more statement that could fail mid-migration.Swapped
print()forloguru.loggerin the cleanup function — loguru is already imported at the top of the file and works fine at migration time.Why
A review of the 0039 migration flagged three concerns: the FTS dedupe was unreachable code, the ACL index was being maintained row-by-row during a bulk UPDATE instead of built once at the end, and
_remove_non_comic_comicsrelied entirely onPath.is_file()to protect legitimate comics — meaning a misconfigured volume mount could escalate into mass deletion. Page-count + sentinel together make it virtually impossible for the cleanup to delete a real comic regardless of FS state.Test plan
uv run python bin/manage.py migrateapplies cleanly through 0039 on a fresh DB; sentinel correctly logs "no comic-suffix paths" and bails out instead of deleting.ruff checkpasses on the migration file.pytest tests/— 26 passed.🤖 Generated with Claude Code