1
0
Fork 0

Optimize notification endpoint

This commit is contained in:
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

View file

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