mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-19 00:18:56 +01:00
Update:Lock file update scans from watcher and queue file updates so that 2 watcher scans never occur simultaneously #906
This commit is contained in:
parent
a73b72a07b
commit
7e05804bcf
@ -28,6 +28,10 @@ class Scanner {
|
|||||||
this.cancelLibraryScan = {}
|
this.cancelLibraryScan = {}
|
||||||
this.librariesScanning = []
|
this.librariesScanning = []
|
||||||
|
|
||||||
|
// Watcher file update scan vars
|
||||||
|
this.pendingFileUpdatesToScan = []
|
||||||
|
this.scanningFilesChanged = false
|
||||||
|
|
||||||
this.bookFinder = new BookFinder()
|
this.bookFinder = new BookFinder()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,7 +498,16 @@ class Scanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async scanFilesChanged(fileUpdates) {
|
async scanFilesChanged(fileUpdates) {
|
||||||
if (!fileUpdates.length) return
|
if (!fileUpdates || !fileUpdates.length) return
|
||||||
|
|
||||||
|
// If already scanning files from watcher then add these updates to queue
|
||||||
|
if (this.scanningFilesChanged) {
|
||||||
|
this.pendingFileUpdatesToScan.push(fileUpdates)
|
||||||
|
Logger.debug(`[Scanner] Already scanning files from watcher - file updates pushed to queue (size ${this.pendingFileUpdatesToScan.length})`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.scanningFilesChanged = true
|
||||||
|
|
||||||
// files grouped by folder
|
// files grouped by folder
|
||||||
var folderGroups = this.getFileUpdatesGrouped(fileUpdates)
|
var folderGroups = this.getFileUpdatesGrouped(fileUpdates)
|
||||||
|
|
||||||
@ -520,6 +533,13 @@ class Scanner {
|
|||||||
var folderScanResults = await this.scanFolderUpdates(library, folder, fileUpdateGroup)
|
var folderScanResults = await this.scanFolderUpdates(library, folder, fileUpdateGroup)
|
||||||
Logger.debug(`[Scanner] Folder scan results`, folderScanResults)
|
Logger.debug(`[Scanner] Folder scan results`, folderScanResults)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.scanningFilesChanged = false
|
||||||
|
|
||||||
|
if (this.pendingFileUpdatesToScan.length) {
|
||||||
|
Logger.debug(`[Scanner] File updates finished scanning with more updates in queue (${this.pendingFileUpdatesToScan.length})`)
|
||||||
|
this.scanFilesChanged(this.pendingFileUpdatesToScan.shift())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async scanFolderUpdates(library, folder, fileUpdateGroup) {
|
async scanFolderUpdates(library, folder, fileUpdateGroup) {
|
||||||
|
Loading…
Reference in New Issue
Block a user