mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-11-07 16:44:16 +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
|
||||
const itemsInProgressPayload = await libraryFilters.getMediaItemsInProgress(library, user, include, limit, false)
|
||||
if (itemsInProgressPayload.items.length) {
|
||||
const ebookOnlyItemsInProgress = itemsInProgressPayload.items.filter(li => li.media.isEBookOnly)
|
||||
const audioOnlyItemsInProgress = itemsInProgressPayload.items.filter(li => !li.media.isEBookOnly)
|
||||
|
||||
shelves.push({
|
||||
id: 'continue-listening',
|
||||
label: 'Continue Listening',
|
||||
labelStringKey: 'LabelContinueListening',
|
||||
type: library.isPodcast ? 'episode' : 'book',
|
||||
entities: itemsInProgressPayload.items,
|
||||
entities: audioOnlyItemsInProgress,
|
||||
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 (library.isBook) {
|
||||
// "Continue Reading" shelf
|
||||
const ebooksInProgressPayload = await libraryFilters.getMediaItemsInProgress(library, user, include, limit, true)
|
||||
if (ebooksInProgressPayload.items.length) {
|
||||
if (ebookOnlyItemsInProgress.length) {
|
||||
// "Continue Reading" shelf
|
||||
shelves.push({
|
||||
id: 'continue-reading',
|
||||
label: 'Continue Reading',
|
||||
labelStringKey: 'LabelContinueReading',
|
||||
type: 'book',
|
||||
entities: ebooksInProgressPayload.items,
|
||||
total: ebooksInProgressPayload.count
|
||||
entities: ebookOnlyItemsInProgress,
|
||||
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()
|
||||
// "Continue Series" shelf
|
||||
const continueSeriesPayload = await libraryFilters.getLibraryItemsContinueSeries(library, user, include, limit)
|
||||
@ -599,35 +600,35 @@ module.exports = (sequelize) => {
|
||||
|
||||
start = Date.now()
|
||||
// "Listen Again" shelf
|
||||
const listenAgainPayload = await libraryFilters.getMediaFinished(library, user, include, limit, false)
|
||||
if (listenAgainPayload.items.length) {
|
||||
const mediaFinishedPayload = await libraryFilters.getMediaFinished(library, user, include, limit)
|
||||
if (mediaFinishedPayload.items.length) {
|
||||
const ebookOnlyItemsInProgress = mediaFinishedPayload.items.filter(li => li.media.isEBookOnly)
|
||||
const audioOnlyItemsInProgress = mediaFinishedPayload.items.filter(li => !li.media.isEBookOnly)
|
||||
|
||||
shelves.push({
|
||||
id: 'listen-again',
|
||||
label: 'Listen Again',
|
||||
labelStringKey: 'LabelListenAgain',
|
||||
type: library.isPodcast ? 'episode' : 'book',
|
||||
entities: listenAgainPayload.items,
|
||||
total: listenAgainPayload.count
|
||||
entities: audioOnlyItemsInProgress,
|
||||
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
|
||||
const readAgainPayload = await libraryFilters.getMediaFinished(library, user, include, limit, true)
|
||||
if (readAgainPayload.items.length) {
|
||||
if (ebookOnlyItemsInProgress.length) {
|
||||
shelves.push({
|
||||
id: 'read-again',
|
||||
label: 'Read Again',
|
||||
labelStringKey: 'LabelReadAgain',
|
||||
type: 'book',
|
||||
entities: readAgainPayload.items,
|
||||
total: readAgainPayload.count
|
||||
entities: ebookOnlyItemsInProgress,
|
||||
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()
|
||||
// "Newest Authors" shelf
|
||||
const newestAuthorsPayload = await libraryFilters.getNewestAuthors(library, user, limit)
|
||||
|
@ -41,13 +41,11 @@ module.exports = {
|
||||
* @param {oldUser} user
|
||||
* @param {string[]} include
|
||||
* @param {number} limit
|
||||
* @param {boolean} ebook true if continue reading shelf
|
||||
* @returns {object} { items:LibraryItem[], count:number }
|
||||
*/
|
||||
async getMediaItemsInProgress(library, user, include, limit, ebook = false) {
|
||||
async getMediaItemsInProgress(library, user, include, limit) {
|
||||
if (library.mediaType === 'book') {
|
||||
const filterValue = ebook ? 'ebook-in-progress' : 'audio-in-progress'
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', filterValue, 'progress', true, false, include, limit, 0)
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', 'in-progress', 'progress', true, false, include, limit, 0)
|
||||
return {
|
||||
items: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
@ -81,7 +79,7 @@ module.exports = {
|
||||
*/
|
||||
async getLibraryItemsMostRecentlyAdded(library, user, include, limit) {
|
||||
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 {
|
||||
libraryItems: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
@ -96,7 +94,7 @@ module.exports = {
|
||||
count
|
||||
}
|
||||
} 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 {
|
||||
libraryItems: libraryItems.map(li => {
|
||||
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 {oldUser} user
|
||||
* @param {string[]} include
|
||||
* @param {number} limit
|
||||
* @param {boolean} ebook true if "Read Again" shelf
|
||||
* @returns {object} { items:object[], count:number }
|
||||
*/
|
||||
async getMediaFinished(library, user, include, limit, ebook = false) {
|
||||
if (ebook && library.mediaType !== 'book') return { items: [], count: 0 }
|
||||
|
||||
async getMediaFinished(library, user, include, limit) {
|
||||
if (library.mediaType === 'book') {
|
||||
const filterValue = ebook ? 'ebook-finished' : 'finished'
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', filterValue, 'progress', true, false, include, limit, 0)
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', 'finished', 'progress', true, false, include, limit, 0)
|
||||
return {
|
||||
items: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
@ -198,7 +192,10 @@ module.exports = {
|
||||
|
||||
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
|
||||
@ -292,7 +289,10 @@ module.exports = {
|
||||
|
||||
const { rows: authors, count } = await Database.models.author.findAndCountAll({
|
||||
where: {
|
||||
libraryId: library.id
|
||||
libraryId: library.id,
|
||||
createdAt: {
|
||||
[Sequelize.Op.gte]: new Date(new Date() - (60 * 24 * 60 * 60 * 1000)) // 60 days ago
|
||||
}
|
||||
},
|
||||
include: {
|
||||
model: Database.models.bookAuthor,
|
||||
@ -348,7 +348,7 @@ module.exports = {
|
||||
async getNewestPodcastEpisodes(library, user, limit) {
|
||||
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 {
|
||||
count,
|
||||
libraryItems: libraryItems.map(li => {
|
||||
|
@ -478,6 +478,10 @@ module.exports = {
|
||||
},
|
||||
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)
|
||||
|
@ -125,6 +125,10 @@ module.exports = {
|
||||
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 = []
|
||||
@ -210,6 +214,9 @@ module.exports = {
|
||||
|
||||
const podcastEpisodeIncludes = []
|
||||
let podcastEpisodeWhere = {}
|
||||
let libraryItemWhere = {
|
||||
libraryId
|
||||
}
|
||||
if (filterGroup === 'progress') {
|
||||
podcastEpisodeIncludes.push({
|
||||
model: Database.models.mediaProgress,
|
||||
@ -233,6 +240,10 @@ module.exports = {
|
||||
} else if (filterValue === 'finished') {
|
||||
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 = []
|
||||
@ -254,9 +265,7 @@ module.exports = {
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
where: {
|
||||
libraryId
|
||||
}
|
||||
where: libraryItemWhere
|
||||
}
|
||||
]
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user