mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
fix(youtube-catalog): keep original metadata for a video first seen and rewritten in one run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012RYLVVbErmEFhmiW48uuFK
This commit is contained in:
1 parent
e65b7da7f7
commit
97cd7f4c24
2 files changed
+17
-1
No files matched your search
@@ -176,7 +176,13 @@ def sync_catalog(
|
||||
prev = existing.get(vid)
|
||||
if prev is None:
|
||||
doc.update(first_seen_at=now, last_changed_at=now)
|
||||
writer.group([(coll.document(vid), doc, False), _history(vid, "first_seen", {}, "observed")])
|
||||
ops = [(coll.document(vid), doc, False), _history(vid, "first_seen", {}, "observed")]
|
||||
if vid in pre_update:
|
||||
# Rewritten in the same run it was first seen: keep the original.
|
||||
ours = _diff(metadata_from_video(pre_update[vid]), meta)
|
||||
if ours:
|
||||
ops.append(_history(vid, "changed", ours, "backfill"))
|
||||
writer.group(ops)
|
||||
stats["new"] += 1
|
||||
continue
|
||||
|
||||
|
||||
@@ -272,3 +272,13 @@ def test_large_sync_commits_in_multiple_batches_without_splitting_pairs():
|
||||
hist = {p.split("/")[1] for p in b if "/history/" in p}
|
||||
assert docs == hist
|
||||
assert len(db.collection(catalog.COLLECTION).docs()) == 450
|
||||
|
||||
|
||||
def test_new_video_rewritten_in_same_run_keeps_original_in_history():
|
||||
db = MemDB()
|
||||
_sync(db, {"a": _video("a", desc="new template")}, T0, pre={"a": _video("a", desc="upload description")})
|
||||
events = sorted((h["event"], h["source"]) for h in _history(db, "a"))
|
||||
assert events == [("changed", "backfill"), ("first_seen", "observed")]
|
||||
changed = [h for h in _history(db, "a") if h["event"] == "changed"][0]
|
||||
assert changed["changes"]["description"] == {"old": "upload description", "new": "new template"}
|
||||
assert _doc(db, "a")["description"] == "new template"
|
||||
Reference in new issue
Block a user