mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-12 12:21:34 +00:00
Limit collections to return only 2 items when getting list of ALL collections (otherwise, return the entire collection)
This commit is contained in:
parent
36f46072fd
commit
44ff2e7a99
2 changed files with 15 additions and 10 deletions
|
|
@ -492,7 +492,7 @@ class LibraryController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Create paginated queries
|
// TODO: Create paginated queries
|
||||||
let collections = await Database.collectionModel.getOldCollectionsJsonExpanded(req.user, req.library.id, include)
|
let collections = await Database.collectionModel.getOldCollectionsJsonExpanded(req.user, req.library.id, include, 2)
|
||||||
|
|
||||||
payload.total = collections.length
|
payload.total = collections.length
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,10 @@ class Collection extends Model {
|
||||||
* @param {[oldUser]} user
|
* @param {[oldUser]} user
|
||||||
* @param {[string]} libraryId
|
* @param {[string]} libraryId
|
||||||
* @param {[string[]]} include
|
* @param {[string[]]} include
|
||||||
|
* @param {[number]} limitCollectionSize
|
||||||
* @returns {Promise<object[]>} oldCollection.toJSONExpanded
|
* @returns {Promise<object[]>} oldCollection.toJSONExpanded
|
||||||
*/
|
*/
|
||||||
static async getOldCollectionsJsonExpanded(user, libraryId, include) {
|
static async getOldCollectionsJsonExpanded(user, libraryId, include, limitCollectionSize) {
|
||||||
let collectionWhere = null
|
let collectionWhere = null
|
||||||
if (libraryId) {
|
if (libraryId) {
|
||||||
collectionWhere = {
|
collectionWhere = {
|
||||||
|
|
@ -88,7 +89,7 @@ class Collection extends Model {
|
||||||
})
|
})
|
||||||
// TODO: Handle user permission restrictions on initial query
|
// TODO: Handle user permission restrictions on initial query
|
||||||
return collections.map(c => {
|
return collections.map(c => {
|
||||||
const oldCollection = this.getOldCollection(c)
|
const oldCollection = this.getOldCollection(c, limitCollectionSize)
|
||||||
|
|
||||||
// Filter books using user permissions
|
// Filter books using user permissions
|
||||||
const books = c.books?.filter(b => {
|
const books = c.books?.filter(b => {
|
||||||
|
|
@ -200,10 +201,14 @@ class Collection extends Model {
|
||||||
/**
|
/**
|
||||||
* Get old collection from Collection
|
* Get old collection from Collection
|
||||||
* @param {Collection} collectionExpanded
|
* @param {Collection} collectionExpanded
|
||||||
|
* @param {number} limitCollectionSize
|
||||||
* @returns {oldCollection}
|
* @returns {oldCollection}
|
||||||
*/
|
*/
|
||||||
static getOldCollection(collectionExpanded) {
|
static getOldCollection(collectionExpanded, limitCollectionSize) {
|
||||||
const libraryItemIds = collectionExpanded.books?.map(b => b.libraryItem?.id || null).filter(lid => lid) || []
|
let libraryItemIds = collectionExpanded.books?.map(b => b.libraryItem?.id || null).filter(lid => lid) || []
|
||||||
|
if (limitCollectionSize) {
|
||||||
|
libraryItemIds = libraryItemIds.slice(0,limitCollectionSize)
|
||||||
|
}
|
||||||
return new oldCollection({
|
return new oldCollection({
|
||||||
id: collectionExpanded.id,
|
id: collectionExpanded.id,
|
||||||
libraryId: collectionExpanded.libraryId,
|
libraryId: collectionExpanded.libraryId,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue