From 7ddc07f68ad60ac5580b1f0e72e1532630fe5fdd Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sat, 18 May 2024 17:15:37 +0200 Subject: [PATCH] fix: Improve locking logic Signed-off-by: Marcel Klehr --- src/lib/adapters/NextcloudBookmarks.ts | 23 +++++------------------ src/lib/adapters/WebDav.ts | 2 +- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/lib/adapters/NextcloudBookmarks.ts b/src/lib/adapters/NextcloudBookmarks.ts index 395903d1d4..092a6c0394 100644 --- a/src/lib/adapters/NextcloudBookmarks.ts +++ b/src/lib/adapters/NextcloudBookmarks.ts @@ -141,16 +141,15 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes if (this.lockingInterval) { clearInterval(this.lockingInterval) } - if (needLock) { - if (!(await this.acquireLock())) { - throw new ResourceLockedError() - } - this.lockingInterval = setInterval(() => !this.ended && this.acquireLock(), LOCK_INTERVAL) + + // if needLock -- we always need it + if (!(await this.acquireLock())) { + throw new ResourceLockedError() } + this.lockingInterval = setInterval(() => !this.ended && this.acquireLock(), LOCK_INTERVAL) this.canceled = false this.ended = false - } async onSyncComplete(): Promise { @@ -229,18 +228,6 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes } } - async _getChildOrder(folderId:string|number, layers:number):Promise { - const childrenOrderJson = await this.sendRequest( - 'GET', - `index.php/apps/bookmarks/public/rest/v2/folder/${folderId}/childorder` + - (layers ? `?layers=${layers}` : '') - ) - if (!Array.isArray(childrenOrderJson.data)) { - throw new UnexpectedServerResponseError() - } - return childrenOrderJson.data - } - async _getChildFolders(folderId:string|number, layers = 0):Promise { const folderJson = await this.sendRequest( 'GET', diff --git a/src/lib/adapters/WebDav.ts b/src/lib/adapters/WebDav.ts index cdb08178f0..7c891fdff3 100644 --- a/src/lib/adapters/WebDav.ts +++ b/src/lib/adapters/WebDav.ts @@ -102,6 +102,7 @@ export default class WebDavAdapter extends CachingAdapter { if (res.status === 200) { // continue anyway + this.locked = true } else if (res.status === 404) { await this.setLock() } else { @@ -267,7 +268,6 @@ export default class WebDavAdapter extends CachingAdapter { if (needLock) { await this.obtainLock() this.lockingInterval = setInterval(() => this.setLock(), LOCK_INTERVAL) // Set lock every minute - } const resp = await this.pullFromServer()