aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-09 09:01:08 +0100
committerChocobozzz <me@florianbigard.com>2020-01-09 09:27:18 +0100
commit119b16e5acffff1901f23c7a0188c78272453e7d (patch)
tree94edba04cd5f65f58bc5607d0093f14a35970cba
parentc511c3f010c45e08e7736a935bf721527db806c8 (diff)
downloadPeerTube-119b16e5acffff1901f23c7a0188c78272453e7d.tar.gz
PeerTube-119b16e5acffff1901f23c7a0188c78272453e7d.tar.zst
PeerTube-119b16e5acffff1901f23c7a0188c78272453e7d.zip
Optimize notification endpoint
-rw-r--r--server/models/account/user-notification.ts22
1 files changed, 11 insertions, 11 deletions
diff --git a/server/models/account/user-notification.ts b/server/models/account/user-notification.ts
index ccb81b891..a05f30175 100644
--- a/server/models/account/user-notification.ts
+++ b/server/models/account/user-notification.ts
@@ -337,25 +337,25 @@ export class UserNotificationModel extends Model<UserNotificationModel> {
337 ActorFollow: ActorFollowModel 337 ActorFollow: ActorFollowModel
338 338
339 static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) { 339 static listForApi (userId: number, start: number, count: number, sort: string, unread?: boolean) {
340 const where = { userId }
341
340 const query: FindOptions = { 342 const query: FindOptions = {
341 offset: start, 343 offset: start,
342 limit: count, 344 limit: count,
343 order: getSort(sort), 345 order: getSort(sort),
344 where: { 346 where
345 userId
346 }
347 } 347 }
348 348
349 if (unread !== undefined) query.where['read'] = !unread 349 if (unread !== undefined) query.where['read'] = !unread
350 350
351 return UserNotificationModel.scope(ScopeNames.WITH_ALL) 351 return Promise.all([
352 .findAndCountAll(query) 352 UserNotificationModel.count({ where })
353 .then(({ rows, count }) => { 353 .then(count => count || 0),
354 return { 354
355 data: rows, 355 count === 0
356 total: count 356 ? []
357 } 357 : UserNotificationModel.scope(ScopeNames.WITH_ALL).findAll(query)
358 }) 358 ]).then(([ total, data ]) => ({ total, data }))
359 } 359 }
360 360
361 static markAsRead (userId: number, notificationIds: number[]) { 361 static markAsRead (userId: number, notificationIds: number[]) {