Fix duplicate theme insertion when API returns multiple versions
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -205,11 +205,13 @@ class AnimeThemesService:
|
|||||||
|
|
||||||
key = (theme_type, sequence)
|
key = (theme_type, sequence)
|
||||||
if key in existing_themes:
|
if key in existing_themes:
|
||||||
# Update existing theme
|
# Update existing theme (skip if already has video_url)
|
||||||
theme = existing_themes[key]
|
theme = existing_themes[key]
|
||||||
|
if not theme.song_title:
|
||||||
theme.song_title = song_title
|
theme.song_title = song_title
|
||||||
|
if not theme.artist:
|
||||||
theme.artist = artist
|
theme.artist = artist
|
||||||
if video_url:
|
if video_url and not theme.animethemes_video_url:
|
||||||
theme.animethemes_video_url = video_url
|
theme.animethemes_video_url = video_url
|
||||||
else:
|
else:
|
||||||
# Create new theme
|
# Create new theme
|
||||||
@@ -225,6 +227,8 @@ class AnimeThemesService:
|
|||||||
if anime.themes is None:
|
if anime.themes is None:
|
||||||
anime.themes = []
|
anime.themes = []
|
||||||
anime.themes.append(theme)
|
anime.themes.append(theme)
|
||||||
|
# Add to existing_themes to avoid duplicates from API
|
||||||
|
existing_themes[key] = theme
|
||||||
|
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user