update generating of term of defences endpoint - optimize insert query

This commit is contained in:
dominik24c 2022-11-24 23:01:35 +01:00
parent faa00ab353
commit fc3d84aa80

View File

@ -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)
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!"}