From fc3d84aa80c1c714863faa4fa0ef54184af7618f Mon Sep 17 00:00:00 2001 From: dominik24c Date: Thu, 24 Nov 2022 23:01:35 +0100 Subject: [PATCH] update generating of term of defences endpoint - optimize insert query --- backend/app/coordinator/routes/enrollments.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/app/coordinator/routes/enrollments.py b/backend/app/coordinator/routes/enrollments.py index a069031..a7a29f8 100644 --- a/backend/app/coordinator/routes/enrollments.py +++ b/backend/app/coordinator/routes/enrollments.py @@ -38,20 +38,18 @@ def generate_term_of_defence_for_this_examination_schedule(examination_schedule_ abort(404, "Not found temporary availabilities for project supervisors") dates = generate_range_dates(ex.start_date, ex.end_date, ex.duration_time) - print(temporary_availabilities) + + term_of_defences = [] for d in dates: e = d + datetime.timedelta(minutes=ex.duration_time) t = list(filter(lambda ta: ta.start_date <= d and ta.end_date >= e, temporary_availabilities)) if len(t) >= limit: - print(f'{d} -- {e}') - print(t) - print("IN") projects_supervisors = [t[i].project_supervisor for i in range(limit)] term_of_defence = TermOfDefence(start_date=d, end_date=e, examination_schedule_id=examination_schedule_id) term_of_defence.members_of_committee = projects_supervisors - db.session.add(term_of_defence) - db.session.commit() - + term_of_defences.append(term_of_defence) + db.session.add_all(term_of_defences) + db.session.commit() return {"message": "Term of defences was generated!"} @@ -78,7 +76,7 @@ def clear_generated_term_of_defences(examination_schedule_id: int) -> dict: if len(td) == 0: break td[0:10] = [] - + # print(len(get_debug_queries())) return {"message": "Term of defences was deleted!"}