Skip to content

Commit 1154a74

Browse files
committed
acquire mutex in proofreading and release after saving
1 parent e02d4ce commit 1154a74

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) {
@@ -704,6 +708,7 @@ function* handleProofreadMergeOrMinCut(action: Action) {
704708
const allowUpdate = yield* select((state) => state.annotation.restrictions.allowUpdate);
705709
if (!allowUpdate) return;
706710

711+
const annotationId = yield* select((state) => state.annotation.annotationId);
707712
const preparation = yield* call(prepareSplitOrMerge, false);
708713
if (!preparation) {
709714
return;
@@ -789,6 +794,7 @@ function* handleProofreadMergeOrMinCut(action: Action) {
789794

790795
yield* put(pushSaveQueueTransaction(items));
791796
yield* call([Model, Model.ensureSavedState]);
797+
yield* call(releaseAnnotationMutex, annotationId);
792798

793799
if (action.type === "MIN_CUT_AGGLOMERATE") {
794800
console.log("start updating the mapping after a min-cut");
@@ -893,6 +899,7 @@ function* handleProofreadCutFromNeighbors(action: Action) {
893899
const allowUpdate = yield* select((state) => state.annotation.restrictions.allowUpdate);
894900
if (!allowUpdate) return;
895901

902+
const annotationId = yield* select((state) => state.annotation.annotationId);
896903
const preparation = yield* call(prepareSplitOrMerge, false);
897904
if (!preparation) {
898905
return;
@@ -947,6 +954,7 @@ function* handleProofreadCutFromNeighbors(action: Action) {
947954

948955
yield* put(pushSaveQueueTransaction(items));
949956
yield* call([Model, Model.ensureSavedState]);
957+
yield* call(releaseAnnotationMutex, annotationId);
950958

951959
// Now that the changes are saved, we can split the mapping locally (because it requires
952960
// communication with the back-end).
@@ -1130,6 +1138,13 @@ function* prepareSplitOrMerge(isSkeletonProofreading: boolean): Saga<Preparation
11301138
return null;
11311139
}
11321140

1141+
const annotationId = yield* select((state) => state.annotation.annotationId);
1142+
const { canEdit } = yield* call(acquireAnnotationMutex, annotationId);
1143+
if (!canEdit) {
1144+
Toast.error("Could not acquire mutex. Somebody else is proofreading at the moment.");
1145+
return null;
1146+
}
1147+
11331148
return {
11341149
agglomerateFileMag,
11351150
getDataValue,

0 commit comments

Comments
 (0)