6
0
Эх сурвалжийг харах

reworked result creation and removal a bit

Dimitri Korsch 3 жил өмнө
parent
commit
eacceeca14

+ 7 - 8
pycs/frontend/endpoints/results/CreateResult.py

@@ -52,17 +52,16 @@ class CreateResult(View):
         # start transaction
         with db.session.begin_nested():
             # find full-image labels and remove them
-            for result in file.results.all():
-                if result.type == 'labeled-image':
-                    removed.append(result.serialize())
-                    result.remove(commit=True)
+            results = file.results.filter_by(type='labeled-image')
+            for result in results.all():
+                removed.append(result.serialize())
+            results.delete()
 
-            # insert into database
-            new_result = file.create_result('user', rtype, label, data,
-                commit=False)
+        # insert into database
+        new_result = file.create_result('user', rtype, label, data)
 
         for result in removed:
-            NotificationManager.removed("result", result.serialize())
+            NotificationManager.removed("result", result)
 
         NotificationManager.created("result", new_result.id, Result)
         return jsonify(new_result)

+ 3 - 4
pycs/frontend/endpoints/results/RemoveResult.py

@@ -26,9 +26,8 @@ class RemoveResult(View):
         if result is None:
             return abort(404)
 
-        # start transaction
-        with db.session.begin_nested():
-            result.remove()
+        result_dump = result.serialize()
+        result.remove()
 
-        NotificationManager.removed("result", result.serialize())
+        NotificationManager.removed("result", result_dump)
         return make_response()