mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Update home page queries merging listen/read shelves, limit recent shelves to 60 days out
This commit is contained in:
		
							parent
							
								
									fbb5fd41fb
								
							
						
					
					
						commit
						33e04d0cbb
					
				| @ -493,33 +493,34 @@ module.exports = (sequelize) => { | |||||||
|       // "Continue Listening" shelf
 |       // "Continue Listening" shelf
 | ||||||
|       const itemsInProgressPayload = await libraryFilters.getMediaItemsInProgress(library, user, include, limit, false) |       const itemsInProgressPayload = await libraryFilters.getMediaItemsInProgress(library, user, include, limit, false) | ||||||
|       if (itemsInProgressPayload.items.length) { |       if (itemsInProgressPayload.items.length) { | ||||||
|  |         const ebookOnlyItemsInProgress = itemsInProgressPayload.items.filter(li => li.media.isEBookOnly) | ||||||
|  |         const audioOnlyItemsInProgress = itemsInProgressPayload.items.filter(li => !li.media.isEBookOnly) | ||||||
|  | 
 | ||||||
|         shelves.push({ |         shelves.push({ | ||||||
|           id: 'continue-listening', |           id: 'continue-listening', | ||||||
|           label: 'Continue Listening', |           label: 'Continue Listening', | ||||||
|           labelStringKey: 'LabelContinueListening', |           labelStringKey: 'LabelContinueListening', | ||||||
|           type: library.isPodcast ? 'episode' : 'book', |           type: library.isPodcast ? 'episode' : 'book', | ||||||
|           entities: itemsInProgressPayload.items, |           entities: audioOnlyItemsInProgress, | ||||||
|           total: itemsInProgressPayload.count |           total: itemsInProgressPayload.count | ||||||
|         }) |         }) | ||||||
|       } |  | ||||||
|       Logger.debug(`Loaded ${itemsInProgressPayload.items.length} of ${itemsInProgressPayload.count} items for "Continue Listening" in ${((Date.now() - fullStart) / 1000).toFixed(2)}s`) |  | ||||||
| 
 | 
 | ||||||
|       let start = Date.now() |         if (ebookOnlyItemsInProgress.length) { | ||||||
|       if (library.isBook) { |           // "Continue Reading" shelf
 | ||||||
|         // "Continue Reading" shelf
 |  | ||||||
|         const ebooksInProgressPayload = await libraryFilters.getMediaItemsInProgress(library, user, include, limit, true) |  | ||||||
|         if (ebooksInProgressPayload.items.length) { |  | ||||||
|           shelves.push({ |           shelves.push({ | ||||||
|             id: 'continue-reading', |             id: 'continue-reading', | ||||||
|             label: 'Continue Reading', |             label: 'Continue Reading', | ||||||
|             labelStringKey: 'LabelContinueReading', |             labelStringKey: 'LabelContinueReading', | ||||||
|             type: 'book', |             type: 'book', | ||||||
|             entities: ebooksInProgressPayload.items, |             entities: ebookOnlyItemsInProgress, | ||||||
|             total: ebooksInProgressPayload.count |             total: itemsInProgressPayload.count | ||||||
|           }) |           }) | ||||||
|         } |         } | ||||||
|         Logger.debug(`Loaded ${ebooksInProgressPayload.items.length} of ${ebooksInProgressPayload.count} items for "Continue Reading" in ${((Date.now() - start) / 1000).toFixed(2)}s`) |       } | ||||||
|  |       Logger.debug(`Loaded ${itemsInProgressPayload.items.length} of ${itemsInProgressPayload.count} items for "Continue Listening/Reading" in ${((Date.now() - fullStart) / 1000).toFixed(2)}s`) | ||||||
| 
 | 
 | ||||||
|  |       let start = Date.now() | ||||||
|  |       if (library.isBook) { | ||||||
|         start = Date.now() |         start = Date.now() | ||||||
|         // "Continue Series" shelf
 |         // "Continue Series" shelf
 | ||||||
|         const continueSeriesPayload = await libraryFilters.getLibraryItemsContinueSeries(library, user, include, limit) |         const continueSeriesPayload = await libraryFilters.getLibraryItemsContinueSeries(library, user, include, limit) | ||||||
| @ -599,35 +600,35 @@ module.exports = (sequelize) => { | |||||||
| 
 | 
 | ||||||
|       start = Date.now() |       start = Date.now() | ||||||
|       // "Listen Again" shelf
 |       // "Listen Again" shelf
 | ||||||
|       const listenAgainPayload = await libraryFilters.getMediaFinished(library, user, include, limit, false) |       const mediaFinishedPayload = await libraryFilters.getMediaFinished(library, user, include, limit) | ||||||
|       if (listenAgainPayload.items.length) { |       if (mediaFinishedPayload.items.length) { | ||||||
|  |         const ebookOnlyItemsInProgress = mediaFinishedPayload.items.filter(li => li.media.isEBookOnly) | ||||||
|  |         const audioOnlyItemsInProgress = mediaFinishedPayload.items.filter(li => !li.media.isEBookOnly) | ||||||
|  | 
 | ||||||
|         shelves.push({ |         shelves.push({ | ||||||
|           id: 'listen-again', |           id: 'listen-again', | ||||||
|           label: 'Listen Again', |           label: 'Listen Again', | ||||||
|           labelStringKey: 'LabelListenAgain', |           labelStringKey: 'LabelListenAgain', | ||||||
|           type: library.isPodcast ? 'episode' : 'book', |           type: library.isPodcast ? 'episode' : 'book', | ||||||
|           entities: listenAgainPayload.items, |           entities: audioOnlyItemsInProgress, | ||||||
|           total: listenAgainPayload.count |           total: mediaFinishedPayload.count | ||||||
|         }) |         }) | ||||||
|       } |  | ||||||
|       Logger.debug(`Loaded ${listenAgainPayload.items.length} of ${listenAgainPayload.count} items for "Listen Again" in ${((Date.now() - start) / 1000).toFixed(2)}s`) |  | ||||||
| 
 | 
 | ||||||
|       if (library.isBook) { |  | ||||||
|         start = Date.now() |  | ||||||
|         // "Read Again" shelf
 |         // "Read Again" shelf
 | ||||||
|         const readAgainPayload = await libraryFilters.getMediaFinished(library, user, include, limit, true) |         if (ebookOnlyItemsInProgress.length) { | ||||||
|         if (readAgainPayload.items.length) { |  | ||||||
|           shelves.push({ |           shelves.push({ | ||||||
|             id: 'read-again', |             id: 'read-again', | ||||||
|             label: 'Read Again', |             label: 'Read Again', | ||||||
|             labelStringKey: 'LabelReadAgain', |             labelStringKey: 'LabelReadAgain', | ||||||
|             type: 'book', |             type: 'book', | ||||||
|             entities: readAgainPayload.items, |             entities: ebookOnlyItemsInProgress, | ||||||
|             total: readAgainPayload.count |             total: mediaFinishedPayload.count | ||||||
|           }) |           }) | ||||||
|         } |         } | ||||||
|         Logger.debug(`Loaded ${readAgainPayload.items.length} of ${readAgainPayload.count} items for "Read Again" in ${((Date.now() - start) / 1000).toFixed(2)}s`) |       } | ||||||
|  |       Logger.debug(`Loaded ${mediaFinishedPayload.items.length} of ${mediaFinishedPayload.count} items for "Listen/Read Again" in ${((Date.now() - start) / 1000).toFixed(2)}s`) | ||||||
| 
 | 
 | ||||||
|  |       if (library.isBook) { | ||||||
|         start = Date.now() |         start = Date.now() | ||||||
|         // "Newest Authors" shelf
 |         // "Newest Authors" shelf
 | ||||||
|         const newestAuthorsPayload = await libraryFilters.getNewestAuthors(library, user, limit) |         const newestAuthorsPayload = await libraryFilters.getNewestAuthors(library, user, limit) | ||||||
|  | |||||||
| @ -41,13 +41,11 @@ module.exports = { | |||||||
|    * @param {oldUser} user  |    * @param {oldUser} user  | ||||||
|    * @param {string[]} include  |    * @param {string[]} include  | ||||||
|    * @param {number} limit  |    * @param {number} limit  | ||||||
|    * @param {boolean} ebook true if continue reading shelf |  | ||||||
|    * @returns {object} { items:LibraryItem[], count:number } |    * @returns {object} { items:LibraryItem[], count:number } | ||||||
|    */ |    */ | ||||||
|   async getMediaItemsInProgress(library, user, include, limit, ebook = false) { |   async getMediaItemsInProgress(library, user, include, limit) { | ||||||
|     if (library.mediaType === 'book') { |     if (library.mediaType === 'book') { | ||||||
|       const filterValue = ebook ? 'ebook-in-progress' : 'audio-in-progress' |       const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', 'in-progress', 'progress', true, false, include, limit, 0) | ||||||
|       const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', filterValue, 'progress', true, false, include, limit, 0) |  | ||||||
|       return { |       return { | ||||||
|         items: libraryItems.map(li => { |         items: libraryItems.map(li => { | ||||||
|           const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified() |           const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified() | ||||||
| @ -81,7 +79,7 @@ module.exports = { | |||||||
|    */ |    */ | ||||||
|   async getLibraryItemsMostRecentlyAdded(library, user, include, limit) { |   async getLibraryItemsMostRecentlyAdded(library, user, include, limit) { | ||||||
|     if (library.mediaType === 'book') { |     if (library.mediaType === 'book') { | ||||||
|       const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, null, null, 'addedAt', true, false, include, limit, 0) |       const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'recent', null, 'addedAt', true, false, include, limit, 0) | ||||||
|       return { |       return { | ||||||
|         libraryItems: libraryItems.map(li => { |         libraryItems: libraryItems.map(li => { | ||||||
|           const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified() |           const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified() | ||||||
| @ -96,7 +94,7 @@ module.exports = { | |||||||
|         count |         count | ||||||
|       } |       } | ||||||
|     } else { |     } else { | ||||||
|       const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredLibraryItems(library.id, user, null, null, 'addedAt', true, include, limit, 0) |       const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredLibraryItems(library.id, user, 'recent', null, 'addedAt', true, include, limit, 0) | ||||||
|       return { |       return { | ||||||
|         libraryItems: libraryItems.map(li => { |         libraryItems: libraryItems.map(li => { | ||||||
|           const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified() |           const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified() | ||||||
| @ -139,20 +137,16 @@ module.exports = { | |||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    * Get library items or podcast episodes for the "Listen Again" or "Read Again" shelf |    * Get library items or podcast episodes for the "Listen Again" and "Read Again" shelf | ||||||
|    * @param {oldLibrary} library  |    * @param {oldLibrary} library  | ||||||
|    * @param {oldUser} user  |    * @param {oldUser} user  | ||||||
|    * @param {string[]} include  |    * @param {string[]} include  | ||||||
|    * @param {number} limit  |    * @param {number} limit  | ||||||
|    * @param {boolean} ebook true if "Read Again" shelf |  | ||||||
|    * @returns {object} { items:object[], count:number } |    * @returns {object} { items:object[], count:number } | ||||||
|    */ |    */ | ||||||
|   async getMediaFinished(library, user, include, limit, ebook = false) { |   async getMediaFinished(library, user, include, limit) { | ||||||
|     if (ebook && library.mediaType !== 'book') return { items: [], count: 0 } |  | ||||||
| 
 |  | ||||||
|     if (library.mediaType === 'book') { |     if (library.mediaType === 'book') { | ||||||
|       const filterValue = ebook ? 'ebook-finished' : 'finished' |       const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', 'finished', 'progress', true, false, include, limit, 0) | ||||||
|       const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', filterValue, 'progress', true, false, include, limit, 0) |  | ||||||
|       return { |       return { | ||||||
|         items: libraryItems.map(li => { |         items: libraryItems.map(li => { | ||||||
|           const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified() |           const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified() | ||||||
| @ -198,7 +192,10 @@ module.exports = { | |||||||
| 
 | 
 | ||||||
|     const seriesWhere = [ |     const seriesWhere = [ | ||||||
|       { |       { | ||||||
|         libraryId: library.id |         libraryId: library.id, | ||||||
|  |         createdAt: { | ||||||
|  |           [Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
 | ||||||
|  |         } | ||||||
|       } |       } | ||||||
|     ] |     ] | ||||||
|     // Handle user permissions to only include series with at least 1 book
 |     // Handle user permissions to only include series with at least 1 book
 | ||||||
| @ -292,7 +289,10 @@ module.exports = { | |||||||
| 
 | 
 | ||||||
|     const { rows: authors, count } = await Database.models.author.findAndCountAll({ |     const { rows: authors, count } = await Database.models.author.findAndCountAll({ | ||||||
|       where: { |       where: { | ||||||
|         libraryId: library.id |         libraryId: library.id, | ||||||
|  |         createdAt: { | ||||||
|  |           [Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
 | ||||||
|  |         } | ||||||
|       }, |       }, | ||||||
|       include: { |       include: { | ||||||
|         model: Database.models.bookAuthor, |         model: Database.models.bookAuthor, | ||||||
| @ -348,7 +348,7 @@ module.exports = { | |||||||
|   async getNewestPodcastEpisodes(library, user, limit) { |   async getNewestPodcastEpisodes(library, user, limit) { | ||||||
|     if (library.mediaType !== 'podcast') return { libraryItems: [], count: 0 } |     if (library.mediaType !== 'podcast') return { libraryItems: [], count: 0 } | ||||||
| 
 | 
 | ||||||
|     const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredPodcastEpisodes(library.id, user, null, null, 'createdAt', true, limit, 0) |     const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredPodcastEpisodes(library.id, user, 'recent', null, 'createdAt', true, limit, 0) | ||||||
|     return { |     return { | ||||||
|       count, |       count, | ||||||
|       libraryItems: libraryItems.map(li => { |       libraryItems: libraryItems.map(li => { | ||||||
|  | |||||||
| @ -478,6 +478,10 @@ module.exports = { | |||||||
|         }, |         }, | ||||||
|         required: false |         required: false | ||||||
|       }) |       }) | ||||||
|  |     } else if (filterGroup === 'recent') { | ||||||
|  |       libraryItemWhere['createdAt'] = { | ||||||
|  |         [Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
 | ||||||
|  |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     let { mediaWhere, replacements } = this.getMediaGroupQuery(filterGroup, filterValue) |     let { mediaWhere, replacements } = this.getMediaGroupQuery(filterGroup, filterValue) | ||||||
|  | |||||||
| @ -125,6 +125,10 @@ module.exports = { | |||||||
|           isInvalid: true |           isInvalid: true | ||||||
|         } |         } | ||||||
|       ] |       ] | ||||||
|  |     } else if (filterGroup === 'recent') { | ||||||
|  |       libraryItemWhere['createdAt'] = { | ||||||
|  |         [Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
 | ||||||
|  |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const podcastIncludes = [] |     const podcastIncludes = [] | ||||||
| @ -210,6 +214,9 @@ module.exports = { | |||||||
| 
 | 
 | ||||||
|     const podcastEpisodeIncludes = [] |     const podcastEpisodeIncludes = [] | ||||||
|     let podcastEpisodeWhere = {} |     let podcastEpisodeWhere = {} | ||||||
|  |     let libraryItemWhere = { | ||||||
|  |       libraryId | ||||||
|  |     } | ||||||
|     if (filterGroup === 'progress') { |     if (filterGroup === 'progress') { | ||||||
|       podcastEpisodeIncludes.push({ |       podcastEpisodeIncludes.push({ | ||||||
|         model: Database.models.mediaProgress, |         model: Database.models.mediaProgress, | ||||||
| @ -233,6 +240,10 @@ module.exports = { | |||||||
|       } else if (filterValue === 'finished') { |       } else if (filterValue === 'finished') { | ||||||
|         podcastEpisodeWhere['$mediaProgresses.isFinished$'] = true |         podcastEpisodeWhere['$mediaProgresses.isFinished$'] = true | ||||||
|       } |       } | ||||||
|  |     } else if (filterGroup === 'recent') { | ||||||
|  |       libraryItemWhere['createdAt'] = { | ||||||
|  |         [Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
 | ||||||
|  |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const podcastEpisodeOrder = [] |     const podcastEpisodeOrder = [] | ||||||
| @ -254,9 +265,7 @@ module.exports = { | |||||||
|           include: [ |           include: [ | ||||||
|             { |             { | ||||||
|               model: Database.models.libraryItem, |               model: Database.models.libraryItem, | ||||||
|               where: { |               where: libraryItemWhere | ||||||
|                 libraryId |  | ||||||
|               } |  | ||||||
|             } |             } | ||||||
|           ] |           ] | ||||||
|         }, |         }, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user