mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-11-03 06:48:18 +00:00
Replace deprecated serialized calls with withLock
This commit is contained in:
1 parent
ffc63fbd4b
commit
72d9e22bc3
11 files changed
+30
-30
No files matched your search
@@ -3,14 +3,14 @@ import type {
|
|||||||
KeyValueDatabaseFactory,
|
KeyValueDatabaseFactory,
|
||||||
} from "@vrtmrz/livesync-commonlib/compat/interfaces/KeyValueDatabase";
|
} from "@vrtmrz/livesync-commonlib/compat/interfaces/KeyValueDatabase";
|
||||||
import { deleteDB, openDB, type IDBPDatabase } from "idb";
|
import { deleteDB, openDB, type IDBPDatabase } from "idb";
|
||||||
import { serialized } from "octagonal-wheels/concurrency/lock";
|
import { withLock } from "octagonal-wheels/concurrency/lock";
|
||||||
|
|
||||||
/** Creates an application-owned IndexedDB key-value factory for browser runtimes. */
|
/** Creates an application-owned IndexedDB key-value factory for browser runtimes. */
|
||||||
export function createBrowserKeyValueDatabaseFactory(): KeyValueDatabaseFactory {
|
export function createBrowserKeyValueDatabaseFactory(): KeyValueDatabaseFactory {
|
||||||
const cache = new Map<string, BrowserKeyValueDatabase>();
|
const cache = new Map<string, BrowserKeyValueDatabase>();
|
||||||
|
|
||||||
return async (databaseKey) =>
|
return async (databaseKey) =>
|
||||||
await serialized(`OpenBrowserKeyValueDatabase-${databaseKey}`, async () => {
|
await withLock(`OpenBrowserKeyValueDatabase-${databaseKey}`, async () => {
|
||||||
const cached = cache.get(databaseKey);
|
const cached = cache.get(databaseKey);
|
||||||
if (cached && !cached.isDestroyed) {
|
if (cached && !cached.isDestroyed) {
|
||||||
return cached;
|
return cached;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { deleteDB, type IDBPDatabase, openDB } from "idb";
|
import { deleteDB, type IDBPDatabase, openDB } from "idb";
|
||||||
import type { KeyValueDatabase } from "@vrtmrz/livesync-commonlib/compat/interfaces/KeyValueDatabase";
|
import type { KeyValueDatabase } from "@vrtmrz/livesync-commonlib/compat/interfaces/KeyValueDatabase";
|
||||||
import { serialized } from "octagonal-wheels/concurrency/lock";
|
import { withLock } from "octagonal-wheels/concurrency/lock";
|
||||||
import { Logger } from "octagonal-wheels/common/logger";
|
import { Logger } from "octagonal-wheels/common/logger";
|
||||||
const databaseCache: { [key: string]: IDBPDatabase<unknown> } = {};
|
const databaseCache: { [key: string]: IDBPDatabase<unknown> } = {};
|
||||||
export { OpenKeyValueDatabase } from "./KeyValueDBv2.ts";
|
export { OpenKeyValueDatabase } from "./KeyValueDBv2.ts";
|
||||||
@@ -13,7 +13,7 @@ export const _OpenKeyValueDatabase = async (dbKey: string): Promise<KeyValueData
|
|||||||
const storeKey = dbKey;
|
const storeKey = dbKey;
|
||||||
let db: IDBPDatabase<unknown> | null = null;
|
let db: IDBPDatabase<unknown> | null = null;
|
||||||
const _openDB = () => {
|
const _openDB = () => {
|
||||||
return serialized("keyvaluedb-" + dbKey, async () => {
|
return withLock("keyvaluedb-" + dbKey, async () => {
|
||||||
const dbInstance = await openDB(dbKey, 1, {
|
const dbInstance = await openDB(dbKey, 1, {
|
||||||
upgrade(db, _oldVersion, _newVersion, _transaction, _event) {
|
upgrade(db, _oldVersion, _newVersion, _transaction, _event) {
|
||||||
return db.createObjectStore(storeKey);
|
return db.createObjectStore(storeKey);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { LOG_LEVEL_VERBOSE, Logger } from "@vrtmrz/livesync-commonlib/compat/common/logger";
|
import { LOG_LEVEL_VERBOSE, Logger } from "@vrtmrz/livesync-commonlib/compat/common/logger";
|
||||||
import type { KeyValueDatabase } from "@vrtmrz/livesync-commonlib/compat/interfaces/KeyValueDatabase";
|
import type { KeyValueDatabase } from "@vrtmrz/livesync-commonlib/compat/interfaces/KeyValueDatabase";
|
||||||
import { deleteDB, openDB, type IDBPDatabase } from "idb";
|
import { deleteDB, openDB, type IDBPDatabase } from "idb";
|
||||||
import { serialized } from "octagonal-wheels/concurrency/lock";
|
import { withLock } from "octagonal-wheels/concurrency/lock";
|
||||||
|
|
||||||
const databaseCache = new Map<string, IDBKeyValueDatabase>();
|
const databaseCache = new Map<string, IDBKeyValueDatabase>();
|
||||||
|
|
||||||
export async function OpenKeyValueDatabase(dbKey: string): Promise<KeyValueDatabase> {
|
export async function OpenKeyValueDatabase(dbKey: string): Promise<KeyValueDatabase> {
|
||||||
return await serialized(`OpenKeyValueDatabase-${dbKey}`, async () => {
|
return await withLock(`OpenKeyValueDatabase-${dbKey}`, async () => {
|
||||||
const cachedDB = databaseCache.get(dbKey);
|
const cachedDB = databaseCache.get(dbKey);
|
||||||
if (cachedDB) {
|
if (cachedDB) {
|
||||||
if (!cachedDB.isDestroyed) {
|
if (!cachedDB.isDestroyed) {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import {
|
|||||||
decodeBinary,
|
decodeBinary,
|
||||||
readString,
|
readString,
|
||||||
} from "@vrtmrz/livesync-commonlib/compat/string_and_binary/convert";
|
} from "@vrtmrz/livesync-commonlib/compat/string_and_binary/convert";
|
||||||
import { serialized, shareRunningResult } from "octagonal-wheels/concurrency/lock";
|
import { withLock, shareRunningResult } from "octagonal-wheels/concurrency/lock";
|
||||||
import { LiveSyncCommands } from "@/features/LiveSyncCommands.ts";
|
import { LiveSyncCommands } from "@/features/LiveSyncCommands.ts";
|
||||||
import { stripAllPrefixes } from "@vrtmrz/livesync-commonlib/compat/string_and_binary/path";
|
import { stripAllPrefixes } from "@vrtmrz/livesync-commonlib/compat/string_and_binary/path";
|
||||||
import { cancelTask, EVEN, isCustomisationSyncMetadata, isPluginMetadata, scheduleTask } from "@/common/utils.ts";
|
import { cancelTask, EVEN, isCustomisationSyncMetadata, isPluginMetadata, scheduleTask } from "@/common/utils.ts";
|
||||||
@@ -752,7 +752,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
// const unifiedFilenameWithKey = this.filenameWithUnifiedKey(updatedDocumentPath);
|
// const unifiedFilenameWithKey = this.filenameWithUnifiedKey(updatedDocumentPath);
|
||||||
const { pathV1 } = this.parseUnifiedPath(unifiedFilenameWithKey);
|
const { pathV1 } = this.parseUnifiedPath(unifiedFilenameWithKey);
|
||||||
|
|
||||||
await serialized(`config:catalogue:${pathV1}`, async () => {
|
await withLock(`config:catalogue:${pathV1}`, async () => {
|
||||||
if (!isCurrent()) return;
|
if (!isCurrent()) return;
|
||||||
const oldEntry = this.pluginList.find((e) => e.documentPath == pathV1);
|
const oldEntry = this.pluginList.find((e) => e.documentPath == pathV1);
|
||||||
let entry: PluginDataExDisplayV2 | undefined = undefined;
|
let entry: PluginDataExDisplayV2 | undefined = undefined;
|
||||||
@@ -925,7 +925,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
path = path.split("%")[1] as FilePath;
|
path = path.split("%")[1] as FilePath;
|
||||||
}
|
}
|
||||||
if (fileA.path.endsWith(".json")) {
|
if (fileA.path.endsWith(".json")) {
|
||||||
return serialized(
|
return withLock(
|
||||||
"config:merge-data",
|
"config:merge-data",
|
||||||
() =>
|
() =>
|
||||||
new Promise<boolean>((res) => {
|
new Promise<boolean>((res) => {
|
||||||
@@ -1276,7 +1276,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
requireCompletion: boolean
|
requireCompletion: boolean
|
||||||
) {
|
) {
|
||||||
const vf = this.filenameWithUnifiedKey(path, term);
|
const vf = this.filenameWithUnifiedKey(path, term);
|
||||||
return await serialized(`plugin-${vf}`, async () => {
|
return await withLock(`plugin-${vf}`, async () => {
|
||||||
const prefixedFileName = vf;
|
const prefixedFileName = vf;
|
||||||
|
|
||||||
const id = await this.path2id(prefixedFileName);
|
const id = await this.path2id(prefixedFileName);
|
||||||
@@ -1379,7 +1379,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
const vf = this.filenameToUnifiedKey(path, term);
|
const vf = this.filenameToUnifiedKey(path, term);
|
||||||
// console.warn(`Storing ${path} to ${bareVF} :--> ${keyedVF}`);
|
// console.warn(`Storing ${path} to ${bareVF} :--> ${keyedVF}`);
|
||||||
|
|
||||||
return await serialized(`plugin-${vf}`, async () => {
|
return await withLock(`plugin-${vf}`, async () => {
|
||||||
const category = this.getFileCategory(path);
|
const category = this.getFileCategory(path);
|
||||||
let mtime = 0;
|
let mtime = 0;
|
||||||
let fileTargets = [] as FilePath[];
|
let fileTargets = [] as FilePath[];
|
||||||
@@ -1683,7 +1683,7 @@ export class ConfigSync extends LiveSyncCommands {
|
|||||||
) {
|
) {
|
||||||
// const id = await this.path2id(prefixedFileName);
|
// const id = await this.path2id(prefixedFileName);
|
||||||
const mtime = new Date().getTime();
|
const mtime = new Date().getTime();
|
||||||
return await serialized("file-x-" + prefixedFileName, async () => {
|
return await withLock("file-x-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
const old = (await this.localDatabase.getDBEntryMeta(prefixedFileName, undefined, false)) as
|
const old = (await this.localDatabase.getDBEntryMeta(prefixedFileName, undefined, false)) as
|
||||||
| InternalFileEntry
|
| InternalFileEntry
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import {
|
|||||||
displayRev,
|
displayRev,
|
||||||
} from "@/common/utils.ts";
|
} from "@/common/utils.ts";
|
||||||
import { PeriodicProcessor } from "@/common/PeriodicProcessor.ts";
|
import { PeriodicProcessor } from "@/common/PeriodicProcessor.ts";
|
||||||
import { serialized, skipIfDuplicated } from "octagonal-wheels/concurrency/lock";
|
import { withLock, skipIfDuplicated } from "octagonal-wheels/concurrency/lock";
|
||||||
import { JsonResolveModal } from "@/features/HiddenFileCommon/JsonResolveModal.ts";
|
import { JsonResolveModal } from "@/features/HiddenFileCommon/JsonResolveModal.ts";
|
||||||
import { LiveSyncCommands } from "@/features/LiveSyncCommands.ts";
|
import { LiveSyncCommands } from "@/features/LiveSyncCommands.ts";
|
||||||
import { addPrefix, stripAllPrefixes } from "@vrtmrz/livesync-commonlib/compat/string_and_binary/path";
|
import { addPrefix, stripAllPrefixes } from "@vrtmrz/livesync-commonlib/compat/string_and_binary/path";
|
||||||
@@ -547,7 +547,7 @@ export class HiddenFileSync extends LiveSyncCommands {
|
|||||||
hiddenFilesEventCount.value++;
|
hiddenFilesEventCount.value++;
|
||||||
const rel = await this.semaphore.acquire();
|
const rel = await this.semaphore.acquire();
|
||||||
try {
|
try {
|
||||||
return await serialized(`hidden-file-event:${file}`, async () => {
|
return await withLock(`hidden-file-event:${file}`, async () => {
|
||||||
hiddenFilesProcessingCount.value++;
|
hiddenFilesProcessingCount.value++;
|
||||||
try {
|
try {
|
||||||
return await fn();
|
return await fn();
|
||||||
@@ -1182,7 +1182,7 @@ Offline Changed files: ${processFiles.length}`;
|
|||||||
|
|
||||||
async applyOfflineChanges(showNotice: boolean) {
|
async applyOfflineChanges(showNotice: boolean) {
|
||||||
const logLevel = getLogLevel(showNotice);
|
const logLevel = getLogLevel(showNotice);
|
||||||
return await serialized("applyOfflineChanges", async () => {
|
return await withLock("applyOfflineChanges", async () => {
|
||||||
const p = this._progress("[⚙ Apply untracked changes ]\n", logLevel);
|
const p = this._progress("[⚙ Apply untracked changes ]\n", logLevel);
|
||||||
this._log(`Track changes.`, logLevel);
|
this._log(`Track changes.`, logLevel);
|
||||||
p.log("Enumerating local files...");
|
p.log("Enumerating local files...");
|
||||||
@@ -1703,7 +1703,7 @@ Offline Changed files: ${files.length}`;
|
|||||||
}
|
}
|
||||||
const prefixedFileName = addPrefix(storeFilePath, ICHeader);
|
const prefixedFileName = addPrefix(storeFilePath, ICHeader);
|
||||||
|
|
||||||
return await serialized("file-" + prefixedFileName, async () => {
|
return await withLock("file-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
const fileInfo = "stat" in file && "body" in file ? file : await this.loadFileWithInfo(storeFilePath);
|
const fileInfo = "stat" in file && "body" in file ? file : await this.loadFileWithInfo(storeFilePath);
|
||||||
if (fileInfo.deleted) {
|
if (fileInfo.deleted) {
|
||||||
@@ -1764,7 +1764,7 @@ Offline Changed files: ${files.length}`;
|
|||||||
}
|
}
|
||||||
const prefixedFileName = addPrefix(storeFilePath, ICHeader);
|
const prefixedFileName = addPrefix(storeFilePath, ICHeader);
|
||||||
|
|
||||||
return await serialized("file-" + prefixedFileName, async () => {
|
return await withLock("file-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
const baseData = await this.getLiveInternalRevision(prefixedFileName, baseRevision);
|
const baseData = await this.getLiveInternalRevision(prefixedFileName, baseRevision);
|
||||||
if (baseData === false) {
|
if (baseData === false) {
|
||||||
@@ -1842,7 +1842,7 @@ Offline Changed files: ${files.length}`;
|
|||||||
if (await this.services.vault.isIgnoredByIgnoreFile(storageFilePath)) {
|
if (await this.services.vault.isIgnoredByIgnoreFile(storageFilePath)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return await serialized("file-" + prefixedFileName, async () => {
|
return await withLock("file-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
const baseData = strict
|
const baseData = strict
|
||||||
? await this.loadBaseSaveDataStrict(storeFilePath, false)
|
? await this.loadBaseSaveDataStrict(storeFilePath, false)
|
||||||
@@ -1913,7 +1913,7 @@ Offline Changed files: ${files.length}`;
|
|||||||
if (await this.services.vault.isIgnoredByIgnoreFile(storageFilePath)) {
|
if (await this.services.vault.isIgnoredByIgnoreFile(storageFilePath)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return await serialized("file-" + prefixedFileName, async () => {
|
return await withLock("file-" + prefixedFileName, async () => {
|
||||||
try {
|
try {
|
||||||
// Check conflicted status
|
// Check conflicted status
|
||||||
const metaOnDB = requiredLiveRevision
|
const metaOnDB = requiredLiveRevision
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from "@vrtmrz/livesync-commonlib/compat/common/types";
|
} from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||||
import { getNoFromRev } from "@vrtmrz/livesync-commonlib/compat/pouchdb/LiveSyncLocalDB";
|
import { getNoFromRev } from "@vrtmrz/livesync-commonlib/compat/pouchdb/LiveSyncLocalDB";
|
||||||
import { LiveSyncCommands } from "@/features/LiveSyncCommands";
|
import { LiveSyncCommands } from "@/features/LiveSyncCommands";
|
||||||
import { serialized } from "octagonal-wheels/concurrency/lock_v2";
|
import { withLock } from "octagonal-wheels/concurrency/lock_v2";
|
||||||
import { arrayToChunkedArray } from "octagonal-wheels/collection";
|
import { arrayToChunkedArray } from "octagonal-wheels/collection";
|
||||||
import { EVENT_REQUEST_PERFORM_GC_V3, eventHub } from "@/common/events";
|
import { EVENT_REQUEST_PERFORM_GC_V3, eventHub } from "@/common/events";
|
||||||
import type { LiveSyncCouchDBReplicator } from "@vrtmrz/livesync-commonlib/compat/replication/couchdb/LiveSyncReplicator";
|
import type { LiveSyncCouchDBReplicator } from "@vrtmrz/livesync-commonlib/compat/replication/couchdb/LiveSyncReplicator";
|
||||||
@@ -435,7 +435,7 @@ Note: **Make sure to synchronise all devices before deletion.**
|
|||||||
chunkSet.add(doc._id);
|
chunkSet.add(doc._id);
|
||||||
} else if ("children" in doc) {
|
} else if ("children" in doc) {
|
||||||
await processDoc(doc, isDeleted);
|
await processDoc(doc, isDeleted);
|
||||||
await serialized("x-process-doc", async () => await processDocRevisions(doc));
|
await withLock("x-process-doc", async () => await processDocRevisions(doc));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Track changes
|
// Track changes
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ vi.mock("octagonal-wheels/number", () => ({
|
|||||||
sizeToHumanReadable: vi.fn((value: number) => `${value} B`),
|
sizeToHumanReadable: vi.fn((value: number) => `${value} B`),
|
||||||
}));
|
}));
|
||||||
vi.mock("octagonal-wheels/concurrency/lock_v2", () => ({
|
vi.mock("octagonal-wheels/concurrency/lock_v2", () => ({
|
||||||
serialized: vi.fn((_key: string, task: () => unknown) => task()),
|
withLock: vi.fn((_key: string, task: () => unknown) => task()),
|
||||||
}));
|
}));
|
||||||
vi.mock("octagonal-wheels/collection", () => ({
|
vi.mock("octagonal-wheels/collection", () => ({
|
||||||
arrayToChunkedArray: vi.fn((values: unknown[]) => [values]),
|
arrayToChunkedArray: vi.fn((values: unknown[]) => [values]),
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import { AbstractObsidianModule } from "@/modules/AbstractObsidianModule.ts";
|
|||||||
import { addIcon, debounce, normalizePath, Notice, stringifyYaml, type WorkspaceLeaf } from "@/deps.ts";
|
import { addIcon, debounce, normalizePath, Notice, stringifyYaml, type WorkspaceLeaf } from "@/deps.ts";
|
||||||
import { LOG_LEVEL_NOTICE, setGlobalLogFunction } from "octagonal-wheels/common/logger";
|
import { LOG_LEVEL_NOTICE, setGlobalLogFunction } from "octagonal-wheels/common/logger";
|
||||||
import { LogPaneView, VIEW_TYPE_LOG } from "./Log/LogPaneView.ts";
|
import { LogPaneView, VIEW_TYPE_LOG } from "./Log/LogPaneView.ts";
|
||||||
import { serialized } from "octagonal-wheels/concurrency/lock";
|
import { withLock } from "octagonal-wheels/concurrency/lock";
|
||||||
import { $msg } from "@/common/translation";
|
import { $msg } from "@/common/translation";
|
||||||
import { P2PLogCollector } from "@vrtmrz/livesync-commonlib/compat/replication/trystero/P2PLogCollector";
|
import { P2PLogCollector } from "@vrtmrz/livesync-commonlib/compat/replication/trystero/P2PLogCollector";
|
||||||
import { REMOTE_REQUEST_ACTIVITY_MINIMUM_VISIBLE_MS, getTrackedRequestCount } from "./RemoteActivityStatus.ts";
|
import { REMOTE_REQUEST_ACTIVITY_MINIMUM_VISIBLE_MS, getTrackedRequestCount } from "./RemoteActivityStatus.ts";
|
||||||
@@ -524,7 +524,7 @@ ${stringifyYaml(info)}
|
|||||||
|
|
||||||
writeLogToTheFile(now: Date, vaultName: string, newMessage: string) {
|
writeLogToTheFile(now: Date, vaultName: string, newMessage: string) {
|
||||||
fireAndForget(() =>
|
fireAndForget(() =>
|
||||||
serialized("writeLog", async () => {
|
withLock("writeLog", async () => {
|
||||||
const time = now.toISOString().split("T")[0];
|
const time = now.toISOString().split("T")[0];
|
||||||
const logDate = `${PREFIXMD_LOGFILE}${time}.md`;
|
const logDate = `${PREFIXMD_LOGFILE}${time}.md`;
|
||||||
const file = await this.core.storageAccess.isExists(normalizePath(logDate));
|
const file = await this.core.storageAccess.isExists(normalizePath(logDate));
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import type { LiveSyncEventHub } from "@vrtmrz/livesync-commonlib/context";
|
|||||||
import type { StorageAccess } from "@vrtmrz/livesync-commonlib/compat/interfaces/StorageAccess";
|
import type { StorageAccess } from "@vrtmrz/livesync-commonlib/compat/interfaces/StorageAccess";
|
||||||
import { EVENT_CONFLICT_CANCELLED } from "@vrtmrz/livesync-commonlib/compat/events/coreEvents";
|
import { EVENT_CONFLICT_CANCELLED } from "@vrtmrz/livesync-commonlib/compat/events/coreEvents";
|
||||||
import { NO_INTERACTION } from "@vrtmrz/livesync-commonlib/replication";
|
import { NO_INTERACTION } from "@vrtmrz/livesync-commonlib/replication";
|
||||||
import { isLockAcquired, serialized } from "octagonal-wheels/concurrency/lock";
|
import { isLockAcquired, withLock } from "octagonal-wheels/concurrency/lock";
|
||||||
import diff_match_patch from "diff-match-patch";
|
import diff_match_patch from "diff-match-patch";
|
||||||
import { stripAllPrefixes, isPlainText } from "@vrtmrz/livesync-commonlib/compat/string_and_binary/path";
|
import { stripAllPrefixes, isPlainText } from "@vrtmrz/livesync-commonlib/compat/string_and_binary/path";
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ export function createConflictResolutionOperations(
|
|||||||
// per-file lock. Dialogues for other paths remain untouched.
|
// per-file lock. Dialogues for other paths remain untouched.
|
||||||
dependencies.events.emitEvent(EVENT_CONFLICT_CANCELLED, filename);
|
dependencies.events.emitEvent(EVENT_CONFLICT_CANCELLED, filename);
|
||||||
}
|
}
|
||||||
return await serialized(serialisationKey, async () => {
|
return await withLock(serialisationKey, async () => {
|
||||||
if (latestResolveRequestByFilename.get(filename) !== requestId) {
|
if (latestResolveRequestByFilename.get(filename) !== requestId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import type {
|
|||||||
import type { LiveSyncLocalDB } from "@vrtmrz/livesync-commonlib/compat/pouchdb/LiveSyncLocalDB";
|
import type { LiveSyncLocalDB } from "@vrtmrz/livesync-commonlib/compat/pouchdb/LiveSyncLocalDB";
|
||||||
import type { LiveSyncEventHub } from "@vrtmrz/livesync-commonlib/context";
|
import type { LiveSyncEventHub } from "@vrtmrz/livesync-commonlib/context";
|
||||||
import { fireAndForget } from "octagonal-wheels/promises";
|
import { fireAndForget } from "octagonal-wheels/promises";
|
||||||
import { serialized } from "octagonal-wheels/concurrency/lock";
|
import { withLock } from "octagonal-wheels/concurrency/lock";
|
||||||
import { NO_INTERACTION } from "@vrtmrz/livesync-commonlib/replication";
|
import { NO_INTERACTION } from "@vrtmrz/livesync-commonlib/replication";
|
||||||
import { displayRev } from "@vrtmrz/livesync-commonlib/compat/common/utils";
|
import { displayRev } from "@vrtmrz/livesync-commonlib/compat/common/utils";
|
||||||
import { EVENT_CONFLICT_CANCELLED, EVENT_ON_UNRESOLVED_ERROR } from "@/common/events.ts";
|
import { EVENT_CONFLICT_CANCELLED, EVENT_ON_UNRESOLVED_ERROR } from "@/common/events.ts";
|
||||||
@@ -160,7 +160,7 @@ export function createInteractiveConflictResolutionOperations(
|
|||||||
// UI for resolving different files should proceed one-by-one. A newer
|
// UI for resolving different files should proceed one-by-one. A newer
|
||||||
// request for the active file replaces its dialogue instead of waiting
|
// request for the active file replaces its dialogue instead of waiting
|
||||||
// behind a comparison which is already stale.
|
// behind a comparison which is already stale.
|
||||||
return await serialized(dialogueSerialisationKey, async () => {
|
return await withLock(dialogueSerialisationKey, async () => {
|
||||||
if (disposed || latestRequestByFilename.get(filename) !== requestId) {
|
if (disposed || latestRequestByFilename.get(filename) !== requestId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
import { fireAndForget, isAnyNote, throttle } from "@vrtmrz/livesync-commonlib/compat/common/utils";
|
import { fireAndForget, isAnyNote, throttle } from "@vrtmrz/livesync-commonlib/compat/common/utils";
|
||||||
import { Semaphore } from "octagonal-wheels/concurrency/semaphore_v2";
|
import { Semaphore } from "octagonal-wheels/concurrency/semaphore_v2";
|
||||||
import { withCounting } from "octagonal-wheels/concurrency/counting";
|
import { withCounting } from "octagonal-wheels/concurrency/counting";
|
||||||
import { serialized } from "octagonal-wheels/concurrency/lock";
|
import { withLock } from "octagonal-wheels/concurrency/lock";
|
||||||
import type { ReactiveSource } from "octagonal-wheels/dataobject/reactive_v2";
|
import type { ReactiveSource } from "octagonal-wheels/dataobject/reactive_v2";
|
||||||
import type { LiveSyncBaseCore } from "@/LiveSyncBaseCore";
|
import type { LiveSyncBaseCore } from "@/LiveSyncBaseCore";
|
||||||
import { isNotFoundError } from "@vrtmrz/livesync-commonlib/compat/common/utils.doc";
|
import { isNotFoundError } from "@vrtmrz/livesync-commonlib/compat/common/utils.doc";
|
||||||
@@ -534,7 +534,7 @@ export class ReplicateResultProcessor {
|
|||||||
private _applyToDatabase(doc_: PouchDB.Core.ExistingDocument<AnyEntry>) {
|
private _applyToDatabase(doc_: PouchDB.Core.ExistingDocument<AnyEntry>) {
|
||||||
const dbDoc = doc_ as LoadedEntry; // It has no `data`
|
const dbDoc = doc_ as LoadedEntry; // It has no `data`
|
||||||
const path = this.getPath(dbDoc);
|
const path = this.getPath(dbDoc);
|
||||||
return serialized(`replication-process:${dbDoc._id}`, async () => {
|
return withLock(`replication-process:${dbDoc._id}`, async () => {
|
||||||
const docNote = `${path} (${shortenId(dbDoc._id)}, ${shortenRev(dbDoc._rev)})`;
|
const docNote = `${path} (${shortenId(dbDoc._id)}, ${shortenRev(dbDoc._rev)})`;
|
||||||
const isRequired = await this.checkIsChangeRequiredForDatabaseProcessing(dbDoc);
|
const isRequired = await this.checkIsChangeRequiredForDatabaseProcessing(dbDoc);
|
||||||
if (!isRequired) {
|
if (!isRequired) {
|
||||||
|
|||||||
Reference in new issue
Block a user