- const query: FindAndCountOptions = {
- offset: start,
- limit: count,
- order: getCommentSort(sort),
- where,
- include: [
- {
- model: AccountModel.unscoped(),
- required: true,
- where: whereAccount,
- include: [
- {
- attributes: {
- exclude: unusedActorAttributesForAPI
- },
- model: ActorModel, // Default scope includes avatar and server
- required: true,
- where: whereActor
- }
- ]
- },
- {
- model: VideoModel.unscoped(),
- required: true,
- where: whereVideo
- }
- ]
+ 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
+ }
+ ]
+ }