Optimize notification endpoint

pull/2396/head
Chocobozzz 2020-01-09 09:01:08 +01:00
parent c511c3f010
commit 119b16e5ac
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 11 additions and 11 deletions

View File

@ -337,25 +337,25 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
ActorFollow: ActorFollowModel
static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) {
const where = { userId }
const query: FindOptions = {
offset: start,
limit: count,
order: getSort(sort),
where: {
userId
}
where
}
if (unread !== undefined) query.where['read'] = !unread
return UserNotificationModel.scope(ScopeNames.WITH_ALL)
.findAndCountAll(query)
.then(({ rows, count }) => {
return {
data: rows,
total: count
}
})
return Promise.all([
UserNotificationModel.count({ where })
.then(count => count || 0),
count === 0
? []
: UserNotificationModel.scope(ScopeNames.WITH_ALL).findAll(query)
]).then(([ total, data ]) => ({ total, data }))
}
static markAsRead (userId: number, notificationIds: number[]) {