Skip to content

Commit a9fa06c

Browse files
committed
fix race condition between getNewestVersionForAnnotation and getUpdateActionLog; remove the former and rely on the latter
1 parent bd536d0 commit a9fa06c

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

frontend/javascripts/viewer/model/sagas/save_saga.ts

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ const VERSION_POLL_INTERVAL_COLLAB = 1 * 1000;
523523
const VERSION_POLL_INTERVAL_READ_ONLY = 1 * 1000;
524524
const VERSION_POLL_INTERVAL_SINGLE_EDITOR = 1 * 1000;
525525

526-
function* watchForSaveConflicts(): Saga<never> {
526+
function* watchForSaveConflicts(): Saga<void> {
527527
function* checkForNewVersion(): Saga<boolean> {
528528
/*
529529
* Checks whether there is a newer version on the server. If so,
@@ -571,42 +571,25 @@ function* watchForSaveConflicts(): Saga<never> {
571571
return false;
572572
}
573573

574-
const versionOnServer = yield* call(
575-
getNewestVersionForAnnotation,
576-
tracingStoreUrl,
577-
annotationId,
578-
);
579-
580-
// Read the tracing version again from the store, since the
581-
// old reference to tracing might be outdated now due to the
582-
// immutability.
583574
const versionOnClient = yield* select((state) => {
584575
return state.annotation.version;
585576
});
586577

587-
const toastKey = "save_conflicts_warning";
588-
const newerVersionCount = versionOnServer - versionOnClient;
589-
if (newerVersionCount > 0) {
590-
// The latest version on the server is greater than the most-recently
591-
// stored version.
592-
593-
const { url: tracingStoreUrl } = yield* select((state) => state.annotation.tracingStore);
578+
// Fetch all update actions that belong to a version that is newer than
579+
// versionOnClient. If there are none, the array will be empty.
580+
// The order is ascending in the version number ([v_n, v_(n+1), ...]).
581+
const newerActions = yield* call(
582+
getUpdateActionLog,
583+
tracingStoreUrl,
584+
annotationId,
585+
versionOnClient + 1,
586+
undefined,
587+
true,
588+
);
594589

590+
const toastKey = "save_conflicts_warning";
591+
if (newerActions.length > 0) {
595592
try {
596-
// The order is ascending in the version number ([v_n, v_(n+1), ...]).
597-
const newerActions = yield* call(
598-
getUpdateActionLog,
599-
tracingStoreUrl,
600-
annotationId,
601-
versionOnClient + 1,
602-
undefined,
603-
true,
604-
);
605-
606-
if (newerActions.length !== newerVersionCount) {
607-
throw new Error("Unexpected size of newer versions.");
608-
}
609-
610593
if ((yield* tryToIncorporateActions(newerActions)).success) {
611594
return false;
612595
}

0 commit comments

Comments
 (0)