From 37b49c1fed91f1d39dffeef9b4b1b6b74872afdc Mon Sep 17 00:00:00 2001 From: Carsten Kvist Date: Tue, 21 Apr 2026 19:27:11 +0200 Subject: [PATCH] Rettet --- linedance-api/app/routers/sync.py | 21 +++++++++++---------- linedance-app/local/sync_manager.py | 16 ++++++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/linedance-api/app/routers/sync.py b/linedance-api/app/routers/sync.py index 42429d55..7621d710 100644 --- a/linedance-api/app/routers/sync.py +++ b/linedance-api/app/routers/sync.py @@ -72,12 +72,13 @@ class PlaylistData(BaseModel): songs: list[PlaylistSongData] = [] class PushPayload(BaseModel): - songs: list[SongData] = [] - dances: list[DanceData] = [] - song_dances: list[SongDanceData] = [] - song_alts: list[SongAltDanceData] = [] - playlists: list[PlaylistData] = [] - deleted_playlists: list[str] = [] # server-IDs (Project.id) + songs: list[SongData] = [] + dances: list[DanceData] = [] + song_dances: list[SongDanceData] = [] + song_alts: list[SongAltDanceData] = [] + playlists: list[PlaylistData] = [] + deleted_playlists: list[str] = [] # server-IDs (Project.id) + songs_with_dances_synced: list[str] = [] # sang-IDs der er fuldt synkroniseret # ── Hjælpefunktion: find eller opret sang globalt ───────────────────────────── @@ -207,10 +208,10 @@ def push( ), {"id": str(uuid.uuid4()), "song_id": song_id, "dance_id": dance_id, "dance_order": sd.dance_order}) - # Sange pushet uden dans-tags — slet også på server - sent_local_ids = {sd.song_local_id for sd in payload.song_dances} - for local_id, song_id in song_id_map.items(): - if local_id in sent_local_ids and song_id not in synced_song_ids: + # Sange der er fuldt synkroniseret men har ingen dans-tags — slet på server + for local_id in payload.songs_with_dances_synced: + song_id = song_id_map.get(local_id) + if song_id and song_id not in synced_song_ids: db.execute(_sa.text("DELETE FROM song_dances WHERE song_id=:sid"), {"sid": song_id}) diff --git a/linedance-app/local/sync_manager.py b/linedance-app/local/sync_manager.py index 49621bb6..575523d1 100644 --- a/linedance-app/local/sync_manager.py +++ b/linedance-app/local/sync_manager.py @@ -245,14 +245,18 @@ class SyncManager: ).fetchall() ] + # Alle sang-IDs der pusher dans-tags fuldt (inkl. dem med 0 tags) + all_song_ids = [s["local_id"] for s in songs] + conn.close() return { - "songs": songs, - "dances": dances, - "song_dances": song_dances, - "song_alts": song_alts, - "playlists": playlists, - "deleted_playlists": deleted, + "songs": songs, + "dances": dances, + "song_dances": song_dances, + "song_alts": song_alts, + "playlists": playlists, + "deleted_playlists": deleted, + "songs_with_dances_synced": all_song_ids, } # ── Gem server-IDs ────────────────────────────────────────────────────────