DB-flush - Server
This commit is contained in:
@@ -156,7 +156,6 @@ def push(
|
||||
# ── Sang-dans tags (brugerens egne) ───────────────────────────────────────
|
||||
from app.models import SongDance, SongAltDance
|
||||
# Slet eksisterende song_dances for disse sange og genindsæt
|
||||
# — sikrer at rækkefølge og ændringer altid er korrekte
|
||||
affected_song_ids = set(
|
||||
song_id_map[sd.song_local_id]
|
||||
for sd in payload.song_dances
|
||||
@@ -166,20 +165,22 @@ def push(
|
||||
db.query(SongDance).filter(
|
||||
SongDance.song_id.in_(affected_song_ids)
|
||||
).delete(synchronize_session=False)
|
||||
db.flush()
|
||||
|
||||
for sd in payload.song_dances:
|
||||
song_id = song_id_map.get(sd.song_local_id)
|
||||
if not song_id:
|
||||
continue
|
||||
level_id = level_map.get(sd.level_name.lower()) if sd.level_name else None
|
||||
key = f"{sd.dance_name.lower()}|{level_id}"
|
||||
dance_id = dance_id_map.get(key)
|
||||
if not dance_id:
|
||||
continue
|
||||
db.add(SongDance(
|
||||
song_id=song_id, dance_id=dance_id,
|
||||
dance_order=sd.dance_order,
|
||||
))
|
||||
with db.no_autoflush:
|
||||
for sd in payload.song_dances:
|
||||
song_id = song_id_map.get(sd.song_local_id)
|
||||
if not song_id:
|
||||
continue
|
||||
level_id = level_map.get(sd.level_name.lower()) if sd.level_name else None
|
||||
key = f"{sd.dance_name.lower()}|{level_id}"
|
||||
dance_id = dance_id_map.get(key)
|
||||
if not dance_id:
|
||||
continue
|
||||
db.add(SongDance(
|
||||
song_id=song_id, dance_id=dance_id,
|
||||
dance_order=sd.dance_order,
|
||||
))
|
||||
|
||||
affected_alt_ids = set(
|
||||
song_id_map[sa.song_local_id]
|
||||
@@ -190,20 +191,22 @@ def push(
|
||||
db.query(SongAltDance).filter(
|
||||
SongAltDance.song_id.in_(affected_alt_ids)
|
||||
).delete(synchronize_session=False)
|
||||
db.flush()
|
||||
|
||||
for sa in payload.song_alts:
|
||||
song_id = song_id_map.get(sa.song_local_id)
|
||||
if not song_id:
|
||||
continue
|
||||
level_id = level_map.get(sa.level_name.lower()) if sa.level_name else None
|
||||
key = f"{sa.dance_name.lower()}|{level_id}"
|
||||
dance_id = dance_id_map.get(key)
|
||||
if not dance_id:
|
||||
continue
|
||||
db.add(SongAltDance(
|
||||
song_id=song_id, dance_id=dance_id,
|
||||
note=sa.note,
|
||||
))
|
||||
with db.no_autoflush:
|
||||
for sa in payload.song_alts:
|
||||
song_id = song_id_map.get(sa.song_local_id)
|
||||
if not song_id:
|
||||
continue
|
||||
level_id = level_map.get(sa.level_name.lower()) if sa.level_name else None
|
||||
key = f"{sa.dance_name.lower()}|{level_id}"
|
||||
dance_id = dance_id_map.get(key)
|
||||
if not dance_id:
|
||||
continue
|
||||
db.add(SongAltDance(
|
||||
song_id=song_id, dance_id=dance_id,
|
||||
note=sa.note,
|
||||
))
|
||||
|
||||
# ── Playlister ────────────────────────────────────────────────────────────
|
||||
playlist_id_map = {}
|
||||
|
||||
Reference in New Issue
Block a user