mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
perf: list albums db query
This commit is contained in:
parent
285e79c5a7
commit
527498bb1e
@ -121,6 +121,16 @@ self.list = async (req, res) => {
|
|||||||
// Base result object
|
// Base result object
|
||||||
const result = { success: true, albums: [], albumsPerPage, count: 0, homeDomain }
|
const result = { success: true, albums: [], albumsPerPage, count: 0, homeDomain }
|
||||||
|
|
||||||
|
// If simple listing (for dashboard sidebar)
|
||||||
|
if (simple) {
|
||||||
|
result.albums = await utils.db.table('albums')
|
||||||
|
.where(filter)
|
||||||
|
.select('id', 'name')
|
||||||
|
result.count = result.albums.length
|
||||||
|
|
||||||
|
return res.json(result)
|
||||||
|
}
|
||||||
|
|
||||||
// Query albums count for pagination
|
// Query albums count for pagination
|
||||||
result.count = await utils.db.table('albums')
|
result.count = await utils.db.table('albums')
|
||||||
.where(filter)
|
.where(filter)
|
||||||
@ -130,16 +140,6 @@ self.list = async (req, res) => {
|
|||||||
return res.json(result)
|
return res.json(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fields = ['id', 'name']
|
|
||||||
|
|
||||||
if (simple) {
|
|
||||||
result.albums = await utils.db.table('albums')
|
|
||||||
.where(filter)
|
|
||||||
.select(fields)
|
|
||||||
|
|
||||||
return res.json(result)
|
|
||||||
}
|
|
||||||
|
|
||||||
let offset = req.path_parameters && Number(req.path_parameters.page)
|
let offset = req.path_parameters && Number(req.path_parameters.page)
|
||||||
if (isNaN(offset)) {
|
if (isNaN(offset)) {
|
||||||
offset = 0
|
offset = 0
|
||||||
@ -147,7 +147,7 @@ self.list = async (req, res) => {
|
|||||||
offset = Math.max(0, Math.ceil(result.count / albumsPerPage) + offset)
|
offset = Math.max(0, Math.ceil(result.count / albumsPerPage) + offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
fields.push('identifier', 'enabled', 'timestamp', 'editedAt', 'zipGeneratedAt', 'download', 'public', 'description')
|
const fields = ['id', 'name', 'identifier', 'enabled', 'timestamp', 'editedAt', 'zipGeneratedAt', 'download', 'public', 'description']
|
||||||
if (all) {
|
if (all) {
|
||||||
fields.push('userid')
|
fields.push('userid')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user