Skip to content

Commit

Permalink
fix: Improve locking logic
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed May 18, 2024
1 parent 755c83c commit 7ddc07f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
23 changes: 5 additions & 18 deletions src/lib/adapters/NextcloudBookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down Expand Up @@ -229,18 +228,6 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
}
}

async _getChildOrder(folderId:string|number, layers:number):Promise<IChildOrderItem[]> {
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<IChildFolder[]> {
const folderJson = await this.sendRequest(
'GET',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adapters/WebDav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7ddc07f

Please sign in to comment.