- return VideoCommentModel
- .findAndCountAll(query)
- .then(({ rows, count }) => {
- return { total: count, data: rows }
- })
+ const getQuery = (forCount: boolean) => {
+ return {
+ offset: start,
+ limit: count,
+ order: getCommentSort(sort),
+ where,
+ include: [
+ {
+ model: AccountModel.unscoped(),
+ required: true,
+ where: whereAccount,
+ include: [
+ {
+ attributes: {
+ exclude: unusedActorAttributesForAPI
+ },
+ model: forCount === true
+ ? ActorModel.unscoped() // Default scope includes avatar and server
+ : ActorModel,
+ required: true,
+ where: whereActor
+ }
+ ]
+ },
+ {
+ model: VideoModel.unscoped(),
+ required: true,
+ where: whereVideo
+ }
+ ]
+ }
+ }
+
+ return Promise.all([
+ VideoCommentModel.count(getQuery(true)),
+ VideoCommentModel.findAll(getQuery(false))
+ ]).then(([ total, data ]) => ({ total, data }))