Skip to content

Commit afe2a94

Browse files
committed
acquire mutex in proofreading and release after saving
1 parent 9220879 commit afe2a94

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

frontend/javascripts/viewer/model/sagas/volume/proofread_saga.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
2+
acquireAnnotationMutex,
23
type NeighborInfo,
34
getAgglomeratesForSegmentsFromTracingstore,
45
getEdgesForAgglomerateMinCut,
56
getNeighborsForAgglomerateNode,
67
getPositionForSegmentInAgglomerate,
8+
releaseAnnotationMutex,
79
} from "admin/rest_api";
810
import { V3 } from "libs/mjs";
911
import Toast from "libs/toast";
@@ -358,6 +360,7 @@ function* handleSkeletonProofreadingAction(action: Action): Saga<void> {
358360
const { agglomerateFileMag, getDataValue, activeMapping, volumeTracing } = preparation;
359361
const { tracingId: volumeTracingId } = volumeTracing;
360362

363+
const annotationId = yield* select((state) => state.annotation.annotationId);
361364
// Use untransformedPosition because agglomerate trees should not have
362365
// any transforms, anyway.
363366
if (yield* select((state) => areGeometriesTransformed(state))) {
@@ -441,6 +444,7 @@ function* handleSkeletonProofreadingAction(action: Action): Saga<void> {
441444

442445
yield* put(pushSaveQueueTransaction(items));
443446
yield* call([Model, Model.ensureSavedState]);
447+
yield* call(releaseAnnotationMutex, annotationId);
444448

445449
if (action.type === "MIN_CUT_AGGLOMERATE_WITH_NODE_IDS" || action.type === "DELETE_EDGE") {
446450
if (sourceAgglomerateId !== targetAgglomerateId) {
@@ -690,6 +694,7 @@ function* handleProofreadMergeOrMinCut(action: Action) {
690694
const allowUpdate = yield* select((state) => state.annotation.restrictions.allowUpdate);
691695
if (!allowUpdate) return;
692696

697+
const annotationId = yield* select((state) => state.annotation.annotationId);
693698
const preparation = yield* call(prepareSplitOrMerge, false);
694699
if (!preparation) {
695700
return;
@@ -775,6 +780,7 @@ function* handleProofreadMergeOrMinCut(action: Action) {
775780

776781
yield* put(pushSaveQueueTransaction(items));
777782
yield* call([Model, Model.ensureSavedState]);
783+
yield* call(releaseAnnotationMutex, annotationId);
778784

779785
if (action.type === "MIN_CUT_AGGLOMERATE") {
780786
console.log("start updating the mapping after a min-cut");
@@ -879,6 +885,7 @@ function* handleProofreadCutFromNeighbors(action: Action) {
879885
const allowUpdate = yield* select((state) => state.annotation.restrictions.allowUpdate);
880886
if (!allowUpdate) return;
881887

888+
const annotationId = yield* select((state) => state.annotation.annotationId);
882889
const preparation = yield* call(prepareSplitOrMerge, false);
883890
if (!preparation) {
884891
return;
@@ -933,6 +940,7 @@ function* handleProofreadCutFromNeighbors(action: Action) {
933940

934941
yield* put(pushSaveQueueTransaction(items));
935942
yield* call([Model, Model.ensureSavedState]);
943+
yield* call(releaseAnnotationMutex, annotationId);
936944

937945
// Now that the changes are saved, we can split the mapping locally (because it requires
938946
// communication with the back-end).
@@ -1116,6 +1124,13 @@ function* prepareSplitOrMerge(isSkeletonProofreading: boolean): Saga<Preparation
11161124
return null;
11171125
}
11181126

1127+
const annotationId = yield* select((state) => state.annotation.annotationId);
1128+
const { canEdit } = yield* call(acquireAnnotationMutex, annotationId);
1129+
if (!canEdit) {
1130+
Toast.error("Could not acquire mutex. Somebody else is proofreading at the moment.");
1131+
return null;
1132+
}
1133+
11191134
return {
11201135
agglomerateFileMag,
11211136
getDataValue,

0 commit comments

Comments
 (0)