mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-20 01:17:45 +02:00
Update library scanner findLibraryItemByItemToFileInoMatch query to iterate through json objects comparing inodes
This commit is contained in:
parent
68276fe30b
commit
f827aa97f8
@ -93,7 +93,7 @@ class Logger {
|
|||||||
|
|
||||||
// Save log to file
|
// Save log to file
|
||||||
if (level >= this.logLevel) {
|
if (level >= this.logLevel) {
|
||||||
await this.logManager.logToFile(logObj)
|
await this.logManager?.logToFile(logObj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const { DataTypes, Model, WhereOptions } = require('sequelize')
|
const { DataTypes, Model } = require('sequelize')
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
const oldLibraryItem = require('../objects/LibraryItem')
|
const oldLibraryItem = require('../objects/LibraryItem')
|
||||||
const libraryFilters = require('../utils/queries/libraryFilters')
|
const libraryFilters = require('../utils/queries/libraryFilters')
|
||||||
@ -116,7 +116,7 @@ class LibraryItem extends Model {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently unused because this is too slow and uses too much mem
|
* Currently unused because this is too slow and uses too much mem
|
||||||
* @param {[WhereOptions]} where
|
* @param {import('sequelize').WhereOptions} [where]
|
||||||
* @returns {Array<objects.LibraryItem>} old library items
|
* @returns {Array<objects.LibraryItem>} old library items
|
||||||
*/
|
*/
|
||||||
static async getAllOldLibraryItems(where = null) {
|
static async getAllOldLibraryItems(where = null) {
|
||||||
@ -773,12 +773,14 @@ class LibraryItem extends Model {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {WhereOptions} where
|
* @param {import('sequelize').WhereOptions} where
|
||||||
|
* @param {import('sequelize').BindOrReplacements} replacements
|
||||||
* @returns {Object} oldLibraryItem
|
* @returns {Object} oldLibraryItem
|
||||||
*/
|
*/
|
||||||
static async findOneOld(where) {
|
static async findOneOld(where, replacements = {}) {
|
||||||
const libraryItem = await this.findOne({
|
const libraryItem = await this.findOne({
|
||||||
where,
|
where,
|
||||||
|
replacements,
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: this.sequelize.models.book,
|
model: this.sequelize.models.book,
|
||||||
|
@ -158,7 +158,7 @@ class LibraryScanner {
|
|||||||
ItemToItemInoMatch(lid, existingLibraryItem) ||
|
ItemToItemInoMatch(lid, existingLibraryItem) ||
|
||||||
ItemToFileInoMatch(lid, existingLibraryItem) ||
|
ItemToFileInoMatch(lid, existingLibraryItem) ||
|
||||||
ItemToFileInoMatch(existingLibraryItem, lid)
|
ItemToFileInoMatch(existingLibraryItem, lid)
|
||||||
)
|
)
|
||||||
if (libraryItemData) {
|
if (libraryItemData) {
|
||||||
libraryScan.addLog(LogLevel.INFO, `Library item with path "${existingLibraryItem.path}" was not found, but library item inode "${existingLibraryItem.ino}" was found at path "${libraryItemData.path}"`)
|
libraryScan.addLog(LogLevel.INFO, `Library item with path "${existingLibraryItem.path}" was not found, but library item inode "${existingLibraryItem.ino}" was found at path "${libraryItemData.path}"`)
|
||||||
}
|
}
|
||||||
@ -635,11 +635,15 @@ async function findLibraryItemByItemToFileInoMatch(libraryId, fullPath, isSingle
|
|||||||
// check if it was moved from another folder by comparing the ino to the library files
|
// check if it was moved from another folder by comparing the ino to the library files
|
||||||
const ino = await fileUtils.getIno(fullPath)
|
const ino = await fileUtils.getIno(fullPath)
|
||||||
if (!ino) return null
|
if (!ino) return null
|
||||||
const existingLibraryItem = await Database.libraryItemModel.findOneOld({
|
const existingLibraryItem = await Database.libraryItemModel.findOneOld([
|
||||||
libraryId: libraryId,
|
{
|
||||||
libraryFiles: {
|
libraryId: libraryId
|
||||||
[ sequelize.Op.substring ]: ino
|
},
|
||||||
}
|
sequelize.where(sequelize.literal('(SELECT count(*) FROM json_each(libraryFiles) WHERE json_valid(json_each.value) AND json_each.value->>"$.ino" = :inode)'), {
|
||||||
|
[sequelize.Op.gt]: 0
|
||||||
|
})
|
||||||
|
], {
|
||||||
|
inode: ino
|
||||||
})
|
})
|
||||||
if (existingLibraryItem)
|
if (existingLibraryItem)
|
||||||
Logger.debug(`[LibraryScanner] Found library item with a library file matching inode "${ino}" at path "${existingLibraryItem.path}"`)
|
Logger.debug(`[LibraryScanner] Found library item with a library file matching inode "${ino}" at path "${existingLibraryItem.path}"`)
|
||||||
@ -658,7 +662,7 @@ async function findLibraryItemByFileToItemInoMatch(libraryId, fullPath, isSingle
|
|||||||
const existingLibraryItem = await Database.libraryItemModel.findOneOld({
|
const existingLibraryItem = await Database.libraryItemModel.findOneOld({
|
||||||
libraryId: libraryId,
|
libraryId: libraryId,
|
||||||
ino: {
|
ino: {
|
||||||
[ sequelize.Op.in ] : itemFileInos
|
[sequelize.Op.in]: itemFileInos
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (existingLibraryItem)
|
if (existingLibraryItem)
|
||||||
|
Loading…
Reference in New Issue
Block a user