refactor(importer): archive tags drop kind prefix

Archive identifier string (artist:archive_name) stays as the tag's
opaque name — the archive kind lives in the kind column.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 15:45:47 -04:00
parent 7f4b1d3ba7
commit 6c767e2427
+10 -10
View File
@@ -946,30 +946,30 @@ def extract_archive_name(filename: str) -> str:
def compute_archive_tag_name(artist: str, archive_filename: str) -> str:
"""
Generate an archive tag name in the format: 'archive:{artist}:{archive_name}'
Generate an archive tag name in the format: '{artist}:{archive_name}'
Similar to post tags (post:{platform}:{artist}:{id}), archive tags use
a consistent prefix and colon-separated components.
Examples:
- artist="InCaseArt", filename="43387617_attachment_83109081_October 2020 Rewards.rar"
-> "archive:InCaseArt:October 2020 Rewards"
-> "InCaseArt:October 2020 Rewards"
If a tag with the same name already exists, appends a numeric suffix.
"""
archive_name = extract_archive_name(archive_filename)
base_tag = f"archive:{artist}:{archive_name}"
base_name = f"{artist}:{archive_name}"
# Check if tag already exists
existing = Tag.query.filter_by(name=base_tag, kind='archive').first()
existing = Tag.query.filter_by(kind='archive', name=base_name).first()
if not existing:
return base_tag
return base_name
# Tag exists, add numeric suffix
n = 2
while True:
candidate = f"{base_tag} ({n})"
if not Tag.query.filter_by(name=candidate, kind='archive').first():
candidate = f"{base_name} ({n})"
if not Tag.query.filter_by(kind='archive', name=candidate).first():
return candidate
n += 1
@@ -978,12 +978,12 @@ def compute_next_archive_tag_name(artist: str, width: int = ARCHIVE_NUM_WIDTH) -
"""
DEPRECATED: Use compute_archive_tag_name() instead.
Return a unique incremental tag name like: 'archive:{artist}/0001', '0002', ...
- Looks only at Tag(kind='archive') with names starting 'archive:{artist}/'
Return a unique incremental tag name like: '{artist}/0001', '0002', ...
- Looks only at Tag(kind='archive') with names starting '{artist}/'
- Finds max numeric suffix and returns next number (zero-padded).
- Ensures no collision even if tags were renamed.
"""
prefix = f"archive:{artist}/"
prefix = f"{artist}/"
# Pull existing tag names for this artist/prefix
rows = (Tag.query
.with_entities(Tag.name)