chore: remove sync_character_fandoms maintenance task
tag.fandom_id is now authoritative. set_tag_fandom auto-applies the fandom tag inline; add_tag already did. There's no drift to sync on a schedule anymore. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -71,7 +71,6 @@ def make_celery(app=None):
|
||||
'app.tasks.scan.cleanup_old_tasks': {'queue': 'maintenance'},
|
||||
'app.tasks.scan.update_system_stats': {'queue': 'maintenance'},
|
||||
'app.tasks.scan.update_batch_stats': {'queue': 'maintenance'},
|
||||
'app.tasks.maintenance.sync_character_fandoms': {'queue': 'maintenance'},
|
||||
|
||||
# Import tasks - handled by worker (heavy processing)
|
||||
'app.tasks.import_file.*': {'queue': 'import'},
|
||||
|
||||
@@ -612,13 +612,6 @@ def trigger_recompute_all_centroids():
|
||||
return redirect(url_for('main.settings', tab='maintenance'))
|
||||
|
||||
|
||||
@main.post('/settings/maintenance/sync-character-fandoms')
|
||||
def trigger_sync_character_fandoms():
|
||||
from app.tasks.maintenance import sync_character_fandoms
|
||||
sync_character_fandoms.apply_async(queue='maintenance')
|
||||
return redirect(url_for('main.settings', tab='maintenance'))
|
||||
|
||||
|
||||
# ----------------------------
|
||||
# Tag add/remove endpoints
|
||||
# ----------------------------
|
||||
|
||||
@@ -1,66 +1,4 @@
|
||||
"""Maintenance-queue Celery tasks. Lightweight, user-triggered, non-ML."""
|
||||
import logging
|
||||
from celery import shared_task
|
||||
from sqlalchemy import text
|
||||
|
||||
from app import db
|
||||
from app.models import Tag
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@shared_task(
|
||||
name='app.tasks.maintenance.sync_character_fandoms',
|
||||
soft_time_limit=120,
|
||||
time_limit=180,
|
||||
)
|
||||
def sync_character_fandoms():
|
||||
"""For every character tag with a non-null fandom_id, attach the fandom
|
||||
tag to every image tagged with the character but not the fandom.
|
||||
|
||||
Additive only — never removes fandom tags.
|
||||
|
||||
Returns a summary dict with counts.
|
||||
"""
|
||||
chars = (
|
||||
Tag.query
|
||||
.filter_by(kind='character')
|
||||
.filter(Tag.fandom_id.isnot(None))
|
||||
.all()
|
||||
)
|
||||
total_added = 0
|
||||
failed = 0
|
||||
for char in chars:
|
||||
try:
|
||||
result = db.session.execute(
|
||||
text("""
|
||||
INSERT INTO image_tags (image_id, tag_id)
|
||||
SELECT it.image_id, :fandom_id
|
||||
FROM image_tags it
|
||||
WHERE it.tag_id = :char_id
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM image_tags it2
|
||||
WHERE it2.image_id = it.image_id
|
||||
AND it2.tag_id = :fandom_id
|
||||
)
|
||||
"""),
|
||||
{'char_id': char.id, 'fandom_id': char.fandom_id},
|
||||
)
|
||||
total_added += result.rowcount or 0
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
failed += 1
|
||||
log.warning(
|
||||
"sync_character_fandoms: char tag %s (%s) failed: %s",
|
||||
char.id, char.name, e,
|
||||
)
|
||||
log.info(
|
||||
"sync_character_fandoms: scanned %d characters, added %d image↔fandom links, %d failed",
|
||||
len(chars), total_added, failed,
|
||||
)
|
||||
return {
|
||||
'characters_scanned': len(chars),
|
||||
'links_added': total_added,
|
||||
'characters_failed': failed,
|
||||
}
|
||||
"""Maintenance-queue Celery tasks. Currently empty — the
|
||||
sync_character_fandoms task was removed on 2026-04-21 as part of the
|
||||
bare-name refactor (tag.fandom_id is now authoritative; no drift to sync).
|
||||
"""
|
||||
|
||||
@@ -456,14 +456,6 @@
|
||||
<button type="submit" class="btn secondary-btn">Recompute all centroids</button>
|
||||
</form>
|
||||
|
||||
<p class="settings-hint mt-paragraph">
|
||||
Attach each character's fandom to every image already tagged with that character.
|
||||
Additive only — existing fandom tags are never removed. Run after you've set a
|
||||
fandom on an existing character, or whenever you suspect drift.
|
||||
</p>
|
||||
<form action="{{ url_for('main.trigger_sync_character_fandoms') }}" method="post" onsubmit="return confirm('Enqueue character↔fandom sync for all tagged images?');">
|
||||
<button type="submit" class="btn secondary-btn">Sync character fandoms to images</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user