diff options
Diffstat (limited to 'server/user_session.py')
-rw-r--r-- | server/user_session.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/server/user_session.py b/server/user_session.py index 976f144..8661016 100644 --- a/server/user_session.py +++ b/server/user_session.py @@ -273,8 +273,8 @@ class UserSession(object): pass db.return_connection(conn) - def update_solution(self, problem_id, trace, solution): - if (trace is None) and (solution is None): + def update_solution(self, problem_id, trace=None, solution=None, done=None): + if (trace is None) and (solution is None) and (done is None): return with self._access_lock: uid = self.uid @@ -283,7 +283,7 @@ class UserSession(object): cur = conn.cursor() try: # TODO: convert to upsert with postgresql 9.5 to eliminate the small window where it's possible for more than one concurrent insert to execute - cur.execute('select id, trace, content from solution where codeq_user_id = %s and problem_id = %s for update', (uid, problem_id)) + cur.execute('select id, trace, content, done from solution where codeq_user_id = %s and problem_id = %s for update', (uid, problem_id)) row = cur.fetchone() if row: if row[1]: @@ -293,7 +293,8 @@ class UserSession(object): else: new_trace = trace new_solution = row[2] if solution is None else solution - cur.execute('update solution set content = %s, trace = %s where id = %s', (new_solution, psycopg2.extras.Json(new_trace), row[0])) + new_done = row[3] if done is None else done + cur.execute('update solution set done = %s, content = %s, trace = %s where id = %s', (new_done, new_solution, psycopg2.extras.Json(new_trace), row[0])) else: # this is the first entry cur.execute('insert into solution (done, content, problem_id, codeq_user_id, trace) values (%s, %s, %s, %s, %s)', (False, solution, problem_id, uid, psycopg2.extras.Json(trace))) |