mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 18:01:42 +00:00
fix: wire browse instrumentation and deep scroll metadata
This commit is contained in:
parent
3489feaf67
commit
26bb34a9ee
8 changed files with 323 additions and 32 deletions
|
|
@ -24,6 +24,10 @@ const libraryFilters = require('../utils/queries/libraryFilters')
|
|||
const libraryItemsPodcastFilters = require('../utils/queries/libraryItemsPodcastFilters')
|
||||
const authorFilters = require('../utils/queries/authorFilters')
|
||||
const zipHelpers = require('../utils/zipHelpers')
|
||||
const {
|
||||
createBrowseRequestProfile,
|
||||
finishBrowseRequestProfile
|
||||
} = require('../utils/queries/libraryBrowseInstrumentation')
|
||||
|
||||
/**
|
||||
* @typedef RequestUserObject
|
||||
|
|
@ -618,6 +622,7 @@ class LibraryController {
|
|||
pageMode: req.query.pageMode || 'paged',
|
||||
nextCursor: null,
|
||||
paginationMode: 'offset',
|
||||
deepScrollAllowed: false,
|
||||
isCountDeferred: false,
|
||||
countMode: 'exact-on-initial-page',
|
||||
sortBy: req.query.sort,
|
||||
|
|
@ -630,6 +635,10 @@ class LibraryController {
|
|||
}
|
||||
|
||||
payload.offset = payload.page * payload.limit
|
||||
const browseProfile = createBrowseRequestProfile({
|
||||
route: 'GET /api/libraries/:id/items',
|
||||
libraryId: req.library.id
|
||||
})
|
||||
|
||||
// TODO: Temporary way of handling collapse sub-series. Either remove feature or handle through sql queries
|
||||
const filterByGroup = payload.filterBy?.split('.').shift()
|
||||
|
|
@ -646,15 +655,24 @@ class LibraryController {
|
|||
payload.total = count
|
||||
payload.results = await libraryHelpers.toCollapsedSeriesPayload(libraryItems, seriesId, req.library.settings.hideSingleBookSeries)
|
||||
} else {
|
||||
const { libraryItems, count, nextCursor, paginationMode, countMode, isCountDeferred } = await Database.libraryItemModel.getByFilterAndSort(req.library, req.user, payload)
|
||||
const { libraryItems, count, nextCursor, paginationMode, deepScrollAllowed, countMode, isCountDeferred } = await Database.libraryItemModel.getByFilterAndSort(req.library, req.user, {
|
||||
...payload,
|
||||
browseProfile
|
||||
})
|
||||
payload.results = libraryItems
|
||||
payload.total = count
|
||||
payload.nextCursor = nextCursor || null
|
||||
payload.paginationMode = paginationMode || 'offset'
|
||||
payload.deepScrollAllowed = !!deepScrollAllowed
|
||||
payload.countMode = countMode || 'exact-on-initial-page'
|
||||
payload.isCountDeferred = !!isCountDeferred
|
||||
}
|
||||
|
||||
const browseSummary = finishBrowseRequestProfile(browseProfile)
|
||||
if (browseSummary.isSlow) {
|
||||
Logger.info('[LibraryController] Slow library browse request', browseSummary)
|
||||
}
|
||||
|
||||
res.json(payload)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue