Closed maihoangbichtram closed 1 week ago
Can you explain what the purpose of these changes is?
Instead of fetching all records and update each record with desired value, I call only 1 update function to update the values that matches the filter conditions.
Each call to API will now there its own db session, instead of 1 db session for all calls to API.
PR reconstruct
Without update func
old_current_solutions = ( db.query(SolutionArchive) .filter(SolutionArchive.problem == problem_id, SolutionArchive.user == user.index, SolutionArchive.current) .all() )
for old in old_current_solutions: old.current = False
With update func
await db.update( update(SolutionArchive) .where(SolutionArchive.problem==problem_id, SolutionArchive.current==True) .values(current=False) )