From a5f80701797e43fcef4a950a3b9bb5751a82fae8 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 25 Sep 2023 17:35:21 +0100 Subject: [PATCH] Improve speaker merging code. --- main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index f1e5990..82b1262 100755 --- a/main.py +++ b/main.py @@ -186,9 +186,20 @@ def merge() -> str | Response: print(other_ids, "->", merge_to_id) + conference_people = model.ConferencePerson.query.filter( + model.ConferencePerson.person_id.in_(other_ids) + ) + with database.session.begin(): + merge_to = model.Person.query.get(merge_to_id) + existing_conferences = {conf.id for conf in merge_to.conferences} + to_delete = [ + cp for cp in conference_people if cp.conference_id in existing_conferences + ] + for cp in to_delete: + database.session.delete(cp) + if merge_to_id != name_from_person_id: - merge_to = model.Person.query.get(merge_to_id) name_from_person = model.Person.query.get(name_from_person_id) merge_to.name = name_from_person.name