fix (ui): select the same episode multiple times
This commit is contained in:
@@ -341,6 +341,21 @@ class SessionService:
|
||||
return self.list_selected_episodes(session_id)
|
||||
|
||||
with self._connect() as conn:
|
||||
existing_rows = conn.execute(
|
||||
"""
|
||||
SELECT payload_json
|
||||
FROM selected_episodes
|
||||
WHERE session_id = ?
|
||||
""",
|
||||
(session_id,),
|
||||
).fetchall()
|
||||
existing_episode_ids: set[str] = set()
|
||||
for row in existing_rows:
|
||||
payload = json.loads(row["payload_json"])
|
||||
episode_id = str(payload.get("id") or "").strip()
|
||||
if episode_id:
|
||||
existing_episode_ids.add(episode_id)
|
||||
|
||||
current_max = conn.execute(
|
||||
"""
|
||||
SELECT COALESCE(MAX(position), -1) AS max_position
|
||||
@@ -352,6 +367,9 @@ class SessionService:
|
||||
next_position = int(current_max["max_position"]) + 1
|
||||
|
||||
for item in items:
|
||||
episode_id = str(item.get("id") or "").strip()
|
||||
if episode_id and episode_id in existing_episode_ids:
|
||||
continue
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO selected_episodes (session_id, position, payload_json)
|
||||
@@ -359,6 +377,8 @@ class SessionService:
|
||||
""",
|
||||
(session_id, next_position, json.dumps(item, ensure_ascii=True)),
|
||||
)
|
||||
if episode_id:
|
||||
existing_episode_ids.add(episode_id)
|
||||
next_position += 1
|
||||
|
||||
return self.list_selected_episodes(session_id)
|
||||
|
||||
Reference in New Issue
Block a user