mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	use already fetched library settings, only fetch maxSequence if setting is turned on
This commit is contained in:
		
							parent
							
								
									c83399c7b5
								
							
						
					
					
						commit
						d4c1bc5dfc
					
				| @ -127,7 +127,7 @@ module.exports = { | |||||||
|    * @returns {object} { libraryItems:LibraryItem[], count:number } |    * @returns {object} { libraryItems:LibraryItem[], count:number } | ||||||
|    */ |    */ | ||||||
|   async getLibraryItemsContinueSeries(library, user, include, limit) { |   async getLibraryItemsContinueSeries(library, user, include, limit) { | ||||||
|     const { libraryItems, count } = await libraryItemsBookFilters.getContinueSeriesLibraryItems(library.id, user, include, limit, 0) |     const { libraryItems, count } = await libraryItemsBookFilters.getContinueSeriesLibraryItems(library, user, include, limit, 0) | ||||||
|     return { |     return { | ||||||
|       libraryItems: libraryItems.map(li => { |       libraryItems: libraryItems.map(li => { | ||||||
|         const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified() |         const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified() | ||||||
|  | |||||||
| @ -640,7 +640,8 @@ module.exports = { | |||||||
|    * @param {number} offset  |    * @param {number} offset  | ||||||
|    * @returns {object} { libraryItems:LibraryItem[], count:number } |    * @returns {object} { libraryItems:LibraryItem[], count:number } | ||||||
|    */ |    */ | ||||||
|   async getContinueSeriesLibraryItems(libraryId, user, include, limit, offset) { |   async getContinueSeriesLibraryItems(library, user, include, limit, offset) { | ||||||
|  |     const libraryId = library.id | ||||||
|     const libraryItemIncludes = [] |     const libraryItemIncludes = [] | ||||||
|     if (include.includes('rssfeed')) { |     if (include.includes('rssfeed')) { | ||||||
|       libraryItemIncludes.push({ |       libraryItemIncludes.push({ | ||||||
| @ -654,6 +655,13 @@ module.exports = { | |||||||
|     const userPermissionBookWhere = this.getUserPermissionBookWhereQuery(user) |     const userPermissionBookWhere = this.getUserPermissionBookWhereQuery(user) | ||||||
|     bookWhere.push(...userPermissionBookWhere.bookWhere) |     bookWhere.push(...userPermissionBookWhere.bookWhere) | ||||||
| 
 | 
 | ||||||
|  |     let includeAttributes = [ | ||||||
|  |       [Sequelize.literal('(SELECT max(mp.updatedAt) FROM bookSeries bs, mediaProgresses mp WHERE mp.mediaItemId = bs.bookId AND mp.userId = :userId AND bs.seriesId = series.id)'), 'recent_progress'], | ||||||
|  |     ] | ||||||
|  |     if (library.settings.onlyShowLaterBooksInContinueSeries) { | ||||||
|  |       includeAttributes.push([Sequelize.literal('(SELECT CAST(max(bs.sequence) as FLOAT) FROM bookSeries bs, mediaProgresses mp WHERE mp.mediaItemId = bs.bookId AND mp.userId = :userId AND bs.seriesId = series.id)'), 'maxSequence']) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     const { rows: series, count } = await Database.seriesModel.findAndCountAll({ |     const { rows: series, count } = await Database.seriesModel.findAndCountAll({ | ||||||
|       where: [ |       where: [ | ||||||
|         { |         { | ||||||
| @ -675,11 +683,7 @@ module.exports = { | |||||||
|         Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM mediaProgresses mp, bookSeries bs WHERE mp.mediaItemId = bs.bookId AND mp.userId = :userId AND bs.seriesId = series.id AND mp.isFinished = 0 AND mp.currentTime > 0)`), 0) |         Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM mediaProgresses mp, bookSeries bs WHERE mp.mediaItemId = bs.bookId AND mp.userId = :userId AND bs.seriesId = series.id AND mp.isFinished = 0 AND mp.currentTime > 0)`), 0) | ||||||
|       ], |       ], | ||||||
|       attributes: { |       attributes: { | ||||||
|         include: [ |         include: includeAttributes | ||||||
|           [Sequelize.literal('(SELECT max(mp.updatedAt) FROM bookSeries bs, mediaProgresses mp WHERE mp.mediaItemId = bs.bookId AND mp.userId = :userId AND bs.seriesId = series.id)'), 'recent_progress'], |  | ||||||
|           [Sequelize.literal('(SELECT CAST(max(bs.sequence) as FLOAT) FROM bookSeries bs, mediaProgresses mp WHERE mp.mediaItemId = bs.bookId AND mp.userId = :userId AND bs.seriesId = series.id)'), 'maxSequence'], |  | ||||||
|           [Sequelize.literal('(SELECT json_extract(libraries.settings, "$.onlyShowLaterBooksInContinueSeries") FROM libraries WHERE id = :libraryId)'), 'onlyShowLaterBooksInContinueSeries'] |  | ||||||
|         ] |  | ||||||
|       }, |       }, | ||||||
|       replacements: { |       replacements: { | ||||||
|         userId: user.id, |         userId: user.id, | ||||||
| @ -737,7 +741,7 @@ module.exports = { | |||||||
| 
 | 
 | ||||||
|       var bookIndex = 0 |       var bookIndex = 0 | ||||||
|       // if the library setting is toggled, only show later entries in series, otherwise skip
 |       // if the library setting is toggled, only show later entries in series, otherwise skip
 | ||||||
|       if (s.dataValues.onlyShowLaterBooksInContinueSeries === 1) { |       if (library.settings.onlyShowLaterBooksInContinueSeries) { | ||||||
|         bookIndex = s.bookSeries.findIndex(function (b) { |         bookIndex = s.bookSeries.findIndex(function (b) { | ||||||
|           return parseFloat(b.dataValues.sequence) > s.dataValues.maxSequence |           return parseFloat(b.dataValues.sequence) > s.dataValues.maxSequence | ||||||
|         }) |         }) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user