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: 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 Similar to post tags (post:{platform}:{artist}:{id}), archive tags use
a consistent prefix and colon-separated components. a consistent prefix and colon-separated components.
Examples: Examples:
- artist="InCaseArt", filename="43387617_attachment_83109081_October 2020 Rewards.rar" - 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. If a tag with the same name already exists, appends a numeric suffix.
""" """
archive_name = extract_archive_name(archive_filename) 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 # 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: if not existing:
return base_tag return base_name
# Tag exists, add numeric suffix # Tag exists, add numeric suffix
n = 2 n = 2
while True: while True:
candidate = f"{base_tag} ({n})" candidate = f"{base_name} ({n})"
if not Tag.query.filter_by(name=candidate, kind='archive').first(): if not Tag.query.filter_by(kind='archive', name=candidate).first():
return candidate return candidate
n += 1 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. DEPRECATED: Use compute_archive_tag_name() instead.
Return a unique incremental tag name like: 'archive:{artist}/0001', '0002', ... Return a unique incremental tag name like: '{artist}/0001', '0002', ...
- Looks only at Tag(kind='archive') with names starting 'archive:{artist}/' - Looks only at Tag(kind='archive') with names starting '{artist}/'
- Finds max numeric suffix and returns next number (zero-padded). - Finds max numeric suffix and returns next number (zero-padded).
- Ensures no collision even if tags were renamed. - Ensures no collision even if tags were renamed.
""" """
prefix = f"archive:{artist}/" prefix = f"{artist}/"
# Pull existing tag names for this artist/prefix # Pull existing tag names for this artist/prefix
rows = (Tag.query rows = (Tag.query
.with_entities(Tag.name) .with_entities(Tag.name)