mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-27 09:08:57 +01:00
Fix library query sort by title, add indexes for books and libraryItems
This commit is contained in:
parent
8c9fc3ddb5
commit
aac2879652
@ -151,7 +151,27 @@ module.exports = (sequelize) => {
|
|||||||
genres: DataTypes.JSON
|
genres: DataTypes.JSON
|
||||||
}, {
|
}, {
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'book'
|
modelName: 'book',
|
||||||
|
indexes: [
|
||||||
|
{
|
||||||
|
fields: [{
|
||||||
|
name: 'title',
|
||||||
|
collate: 'NOCASE'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: [{
|
||||||
|
name: 'titleIgnorePrefix',
|
||||||
|
collate: 'NOCASE'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: ['publishedYear']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: ['duration']
|
||||||
|
}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
return Book
|
return Book
|
||||||
|
@ -63,6 +63,10 @@ module.exports = (sequelize) => {
|
|||||||
*/
|
*/
|
||||||
static getLibraryItemsIncrement(offset, limit) {
|
static getLibraryItemsIncrement(offset, limit) {
|
||||||
return this.findAll({
|
return this.findAll({
|
||||||
|
benchmark: true,
|
||||||
|
logging: (sql, timeMs) => {
|
||||||
|
console.log(`[Query] Elapsed ${timeMs}ms.`)
|
||||||
|
},
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: sequelize.models.book,
|
model: sequelize.models.book,
|
||||||
@ -89,7 +93,7 @@ module.exports = (sequelize) => {
|
|||||||
['createdAt', 'ASC'],
|
['createdAt', 'ASC'],
|
||||||
// Ensure author & series stay in the same order
|
// Ensure author & series stay in the same order
|
||||||
[sequelize.models.book, sequelize.models.author, sequelize.models.bookAuthor, 'createdAt', 'ASC'],
|
[sequelize.models.book, sequelize.models.author, sequelize.models.bookAuthor, 'createdAt', 'ASC'],
|
||||||
[sequelize.models.book, sequelize.models.series, 'bookSeries', 'createdAt', 'ASC'],
|
[sequelize.models.book, sequelize.models.series, 'bookSeries', 'createdAt', 'ASC']
|
||||||
],
|
],
|
||||||
offset,
|
offset,
|
||||||
limit
|
limit
|
||||||
@ -702,6 +706,15 @@ module.exports = (sequelize) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
fields: ['mediaId']
|
fields: ['mediaId']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: ['libraryId', 'mediaType']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: ['birthtime']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fields: ['mtime']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
@ -257,7 +257,7 @@ module.exports = {
|
|||||||
if (global.ServerSettings.sortingIgnorePrefix) {
|
if (global.ServerSettings.sortingIgnorePrefix) {
|
||||||
return [[Sequelize.literal('titleIgnorePrefix COLLATE NOCASE'), dir]]
|
return [[Sequelize.literal('titleIgnorePrefix COLLATE NOCASE'), dir]]
|
||||||
} else {
|
} else {
|
||||||
return [[Sequelize.literal('title COLLATE NOCASE'), dir]]
|
return [[Sequelize.literal('`book`.`title` COLLATE NOCASE'), dir]]
|
||||||
}
|
}
|
||||||
} else if (sortBy === 'sequence') {
|
} else if (sortBy === 'sequence') {
|
||||||
const nullDir = sortDesc ? 'DESC NULLS FIRST' : 'ASC NULLS LAST'
|
const nullDir = sortDesc ? 'DESC NULLS FIRST' : 'ASC NULLS LAST'
|
||||||
@ -546,6 +546,10 @@ module.exports = {
|
|||||||
distinct: true,
|
distinct: true,
|
||||||
attributes: bookAttributes,
|
attributes: bookAttributes,
|
||||||
replacements,
|
replacements,
|
||||||
|
benchmark: true,
|
||||||
|
logging: (sql, timeMs) => {
|
||||||
|
console.log(`[Query] Elapsed ${timeMs}ms.`)
|
||||||
|
},
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Database.models.libraryItem,
|
model: Database.models.libraryItem,
|
||||||
|
Loading…
Reference in New Issue
Block a user