mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 09:51:37 +00:00
test: define large-library browse strategy contract
This commit is contained in:
parent
da490605b7
commit
1533d4146a
4 changed files with 241 additions and 0 deletions
21
server/utils/queries/libraryBrowseCount.js
Normal file
21
server/utils/queries/libraryBrowseCount.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
async function loadBrowseCount({ mode, exactCountLoader } = {}) {
|
||||
if (mode === 'skip') {
|
||||
return {
|
||||
total: null,
|
||||
isExact: false,
|
||||
isDeferred: true
|
||||
}
|
||||
}
|
||||
|
||||
const total = await exactCountLoader()
|
||||
|
||||
return {
|
||||
total,
|
||||
isExact: true,
|
||||
isDeferred: mode === 'deferred-exact'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
loadBrowseCount
|
||||
}
|
||||
63
server/utils/queries/libraryBrowseStrategy.js
Normal file
63
server/utils/queries/libraryBrowseStrategy.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
function getCursorKeys(sortBy) {
|
||||
if (sortBy === 'media.metadata.authorName') {
|
||||
return ['authorNamesFirstLast', 'titleIgnorePrefix', 'id']
|
||||
}
|
||||
|
||||
if (sortBy === 'media.metadata.authorNameLF') {
|
||||
return ['authorNamesLastFirst', 'titleIgnorePrefix', 'id']
|
||||
}
|
||||
|
||||
if (sortBy === 'progress') {
|
||||
return ['mediaProgress.updatedAt', 'id']
|
||||
}
|
||||
|
||||
if (sortBy === 'updatedAt') {
|
||||
return ['updatedAt', 'id']
|
||||
}
|
||||
|
||||
if (sortBy === 'addedAt') {
|
||||
return ['createdAt', 'id']
|
||||
}
|
||||
|
||||
return ['titleIgnorePrefix', 'id']
|
||||
}
|
||||
|
||||
function getFamily({ mediaType, sortBy, filterGroup, collapseseries }) {
|
||||
if (sortBy === 'random') return 'random-browse'
|
||||
if (mediaType === 'podcast') return 'podcast-browse'
|
||||
if (collapseseries && filterGroup === 'series') return 'collapsed-series-browse'
|
||||
if (filterGroup === 'series') return 'series-browse'
|
||||
if (filterGroup === 'progress') return 'progress-browse'
|
||||
if (filterGroup === 'recent' || sortBy === 'addedAt') return 'recent-browse'
|
||||
if (sortBy === 'media.metadata.authorName' || sortBy === 'media.metadata.authorNameLF') return 'author-browse'
|
||||
if (filterGroup) return 'filtered-browse'
|
||||
return 'plain-browse'
|
||||
}
|
||||
|
||||
function getLibraryBrowseStrategy({ mediaType, sortBy, filterGroup, pageMode, collapseseries } = {}) {
|
||||
const normalizedSort = sortBy || 'media.metadata.title'
|
||||
|
||||
if (normalizedSort === 'random') {
|
||||
return {
|
||||
family: 'random-browse',
|
||||
paginationMode: 'offset',
|
||||
countMode: 'exact-on-initial-page',
|
||||
deepScrollAllowed: false,
|
||||
tieBreaker: 'id',
|
||||
cursorKeys: []
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
family: getFamily({ mediaType, sortBy: normalizedSort, filterGroup, collapseseries }),
|
||||
paginationMode: pageMode === 'endless' ? 'keyset' : 'offset',
|
||||
countMode: 'deferred-exact',
|
||||
deepScrollAllowed: true,
|
||||
tieBreaker: 'id',
|
||||
cursorKeys: getCursorKeys(normalizedSort)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getLibraryBrowseStrategy
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue