mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-08 00:08:14 +01:00
Added limit variable to getAuthorsWithCount()
- Clarified and updated the comments - added parameter "limit" to getAuthorsWithCount() - the limit is set to 10 when called from LibraryController.js - as per Nichwall's comments
This commit is contained in:
parent
7229cfce84
commit
5041f80cb0
@ -5,7 +5,7 @@ module.exports = {
|
|||||||
/**
|
/**
|
||||||
* Get authors total count
|
* Get authors total count
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
* @returns {{id:string, name:string, count:number}}
|
* @returns {number} count
|
||||||
*/
|
*/
|
||||||
async getAuthorsTotalCount(libraryId) {
|
async getAuthorsTotalCount(libraryId) {
|
||||||
const authorsCount = await Database.authorModel.count({
|
const authorsCount = await Database.authorModel.count({
|
||||||
@ -19,9 +19,10 @@ module.exports = {
|
|||||||
/**
|
/**
|
||||||
* Get authors with count of num books
|
* Get authors with count of num books
|
||||||
* @param {string} libraryId
|
* @param {string} libraryId
|
||||||
|
* @param {number} limit
|
||||||
* @returns {{id:string, name:string, count:number}}
|
* @returns {{id:string, name:string, count:number}}
|
||||||
*/
|
*/
|
||||||
async getAuthorsWithCount(libraryId) {
|
async getAuthorsWithCount(libraryId, limit) {
|
||||||
const authors = await Database.bookAuthorModel.findAll({
|
const authors = await Database.bookAuthorModel.findAll({
|
||||||
include: [{
|
include: [{
|
||||||
model: Database.authorModel,
|
model: Database.authorModel,
|
||||||
@ -37,7 +38,7 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
group: ['authorId', 'author.id'], // Include 'author.id' to satisfy GROUP BY with JOIN
|
group: ['authorId', 'author.id'], // Include 'author.id' to satisfy GROUP BY with JOIN
|
||||||
order: [[Sequelize.literal('count'), 'DESC']],
|
order: [[Sequelize.literal('count'), 'DESC']],
|
||||||
limit: 10
|
limit: limit
|
||||||
})
|
})
|
||||||
return authors.map(au => {
|
return authors.map(au => {
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user