mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-20 18:59:37 +00:00
Improve page load queries on title, titleIgnorePrefix, and addedAt sort order
This commit is contained in:
parent
52bb28669a
commit
a13143245b
6 changed files with 363 additions and 9 deletions
|
|
@ -3,6 +3,7 @@ const Logger = require('../Logger')
|
|||
const { getTitlePrefixAtEnd, getTitleIgnorePrefix } = require('../utils')
|
||||
const parseNameString = require('../utils/parsers/parseNameString')
|
||||
const htmlSanitizer = require('../utils/htmlSanitizer')
|
||||
const libraryItemsBookFilters = require('../utils/queries/libraryItemsBookFilters')
|
||||
|
||||
/**
|
||||
* @typedef EBookFileObject
|
||||
|
|
@ -192,6 +193,14 @@ class Book extends Model {
|
|||
]
|
||||
}
|
||||
)
|
||||
|
||||
Book.addHook('afterDestroy', async (instance) => {
|
||||
libraryItemsBookFilters.clearCountCache('afterDestroy ')
|
||||
})
|
||||
|
||||
Book.addHook('afterCreate', async (instance) => {
|
||||
libraryItemsBookFilters.clearCountCache('afterCreate')
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -73,6 +73,10 @@ class LibraryItem extends Model {
|
|||
|
||||
/** @type {Book.BookExpanded|Podcast.PodcastExpanded} - only set when expanded */
|
||||
this.media
|
||||
/** @type {string} */
|
||||
this.title // Only used for sorting
|
||||
/** @type {string} */
|
||||
this.titleIgnorePrefix // Only used for sorting
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -677,7 +681,9 @@ class LibraryItem extends Model {
|
|||
lastScan: DataTypes.DATE,
|
||||
lastScanVersion: DataTypes.STRING,
|
||||
libraryFiles: DataTypes.JSON,
|
||||
extraData: DataTypes.JSON
|
||||
extraData: DataTypes.JSON,
|
||||
title: DataTypes.STRING,
|
||||
titleIgnorePrefix: DataTypes.STRING
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
|
|
@ -695,6 +701,12 @@ class LibraryItem extends Model {
|
|||
{
|
||||
fields: ['libraryId', 'mediaType', 'size']
|
||||
},
|
||||
{
|
||||
fields: ['libraryId', 'mediaType', { name: 'title', collate: 'NOCASE' }]
|
||||
},
|
||||
{
|
||||
fields: ['libraryId', 'mediaType', { name: 'titleIgnorePrefix', collate: 'NOCASE' }]
|
||||
},
|
||||
{
|
||||
fields: ['libraryId', 'mediaId', 'mediaType']
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue