mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Fix direct access to Database.libraryFilterData
This commit is contained in:
parent
0d9d2fa4be
commit
0e8148001e
@ -430,7 +430,7 @@ class Database {
|
|||||||
await oldLibraryItem.saveMetadata()
|
await oldLibraryItem.saveMetadata()
|
||||||
const updated = await this.models.libraryItem.fullUpdateFromOld(oldLibraryItem)
|
const updated = await this.models.libraryItem.fullUpdateFromOld(oldLibraryItem)
|
||||||
// Clear library filter data cache
|
// Clear library filter data cache
|
||||||
if (updated) {
|
if (updated) {
|
||||||
delete this.libraryFilterData[oldLibraryItem.libraryId]
|
delete this.libraryFilterData[oldLibraryItem.libraryId]
|
||||||
}
|
}
|
||||||
return updated
|
return updated
|
||||||
@ -689,6 +689,20 @@ class Database {
|
|||||||
return this.libraryFilterData[libraryId].series.some(se => se.id === seriesId)
|
return this.libraryFilterData[libraryId].series.some(se => se.id === seriesId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAuthorByName(libraryId, authorName) {
|
||||||
|
if (!this.libraryFilterData[libraryId]) {
|
||||||
|
return await this.authorModel.getOldByNameAndLibrary(authorName, libraryId)
|
||||||
|
}
|
||||||
|
return this.libraryFilterData[libraryId].authors.find(au => au.name === authorName)
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSeriesByName(libraryId, seriesName) {
|
||||||
|
if (!this.libraryFilterData[libraryId]) {
|
||||||
|
return await this.seriesModel.getOldByNameAndLibrary(seriesName, libraryId)
|
||||||
|
}
|
||||||
|
return this.libraryFilterData[libraryId].series.find(se => se.name === seriesName)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset numIssues for library
|
* Reset numIssues for library
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
|
@ -186,7 +186,7 @@ class BookScanner {
|
|||||||
// Check for authors added
|
// Check for authors added
|
||||||
for (const authorName of bookMetadata.authors) {
|
for (const authorName of bookMetadata.authors) {
|
||||||
if (!media.authors.some(au => au.name === authorName)) {
|
if (!media.authors.some(au => au.name === authorName)) {
|
||||||
const existingAuthor = Database.libraryFilterData[libraryItemData.libraryId].authors.find(au => au.name === authorName)
|
const existingAuthor = await Database.getAuthorByName(libraryItemData.libraryId, authorName)
|
||||||
if (existingAuthor) {
|
if (existingAuthor) {
|
||||||
await Database.bookAuthorModel.create({
|
await Database.bookAuthorModel.create({
|
||||||
bookId: media.id,
|
bookId: media.id,
|
||||||
@ -221,7 +221,7 @@ class BookScanner {
|
|||||||
for (const seriesObj of bookMetadata.series) {
|
for (const seriesObj of bookMetadata.series) {
|
||||||
const existingBookSeries = media.series.find(se => se.name === seriesObj.name)
|
const existingBookSeries = media.series.find(se => se.name === seriesObj.name)
|
||||||
if (!existingBookSeries) {
|
if (!existingBookSeries) {
|
||||||
const existingSeries = Database.libraryFilterData[libraryItemData.libraryId].series.find(se => se.name === seriesObj.name)
|
const existingSeries = await Database.getSeriesByName(libraryItemData.libraryId, seriesObj.name)
|
||||||
if (existingSeries) {
|
if (existingSeries) {
|
||||||
await Database.bookSeriesModel.create({
|
await Database.bookSeriesModel.create({
|
||||||
bookId: media.id,
|
bookId: media.id,
|
||||||
@ -443,7 +443,7 @@ class BookScanner {
|
|||||||
}
|
}
|
||||||
if (bookMetadata.authors.length) {
|
if (bookMetadata.authors.length) {
|
||||||
for (const authorName of bookMetadata.authors) {
|
for (const authorName of bookMetadata.authors) {
|
||||||
const matchingAuthor = Database.libraryFilterData[libraryItemData.libraryId].authors.find(au => au.name === authorName)
|
const matchingAuthor = await Database.getAuthorByName(libraryItemData.libraryId, authorName)
|
||||||
if (matchingAuthor) {
|
if (matchingAuthor) {
|
||||||
bookObject.bookAuthors.push({
|
bookObject.bookAuthors.push({
|
||||||
authorId: matchingAuthor.id
|
authorId: matchingAuthor.id
|
||||||
@ -463,7 +463,7 @@ class BookScanner {
|
|||||||
if (bookMetadata.series.length) {
|
if (bookMetadata.series.length) {
|
||||||
for (const seriesObj of bookMetadata.series) {
|
for (const seriesObj of bookMetadata.series) {
|
||||||
if (!seriesObj.name) continue
|
if (!seriesObj.name) continue
|
||||||
const matchingSeries = Database.libraryFilterData[libraryItemData.libraryId].series.find(se => se.name === seriesObj.name)
|
const matchingSeries = await Database.getSeriesByName(libraryItemData.libraryId, seriesObj.name)
|
||||||
if (matchingSeries) {
|
if (matchingSeries) {
|
||||||
bookObject.bookSeries.push({
|
bookObject.bookSeries.push({
|
||||||
seriesId: matchingSeries.id,
|
seriesId: matchingSeries.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user