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