Fix trending videos count

pull/1011/head
Chocobozzz 2018-09-03 18:05:12 +02:00
parent 74d6346935
commit 8ea6f49ad7
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 104 additions and 92 deletions

View File

@ -1200,7 +1200,19 @@ export class VideoModel extends Model<VideoModel> {
]
}
const { count, rows: rowsId } = await VideoModel.scope(idsScope).findAndCountAll(query)
// Remove trending sort on count, because it uses a group by
const countOptions = Object.assign({}, options, { trendingDays: undefined })
const countQuery = Object.assign({}, query, { attributes: undefined, group: undefined })
const countScope = {
method: [
ScopeNames.AVAILABLE_FOR_LIST_IDS, countOptions
]
}
const [ count, rowsId ] = await Promise.all([
VideoModel.scope(countScope).count(countQuery),
VideoModel.scope(idsScope).findAll(query)
])
const ids = rowsId.map(r => r.id)
if (ids.length === 0) return { data: [], total: count }