From 381605414f161dc4ff7f8fe3d7cd39061b5c7a47 Mon Sep 17 00:00:00 2001 From: Andrew Woodlee Date: Tue, 27 Dec 2022 19:51:32 -0600 Subject: [PATCH] changed counting authors from length to DB --- app/controllers/post.js | 6 ++++-- app/services/user.js | 4 +++- app/views/post/author/all.pug | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/post.js b/app/controllers/post.js index 1aef155..0e21148 100644 --- a/app/controllers/post.js +++ b/app/controllers/post.js @@ -397,8 +397,10 @@ class PostController extends SiteController { const { user: userService } = this.dtp.services; try { res.locals.pagination = this.getPaginationParameters(req, 20); - res.locals.authors = await userService.getAuthors(res.locals.pagination); - + + const {authors , totalAuthorCount }= await userService.getAuthors(res.locals.pagination); + res.locals.authors = authors; + res.locals.totalAuthorCount = totalAuthorCount; res.render('post/author/all'); } catch (error) { return next(error); diff --git a/app/services/user.js b/app/services/user.js index 94b69b8..9b75b01 100644 --- a/app/services/user.js +++ b/app/services/user.js @@ -536,7 +536,9 @@ class UserService extends SiteService { .limit(pagination.cpp) .populate(this.populateUser) .lean(); - return authors; + const totalAuthorCount = await User.countDocuments( {'permissions.canAuthorPosts': true } ); + + return {authors, totalAuthorCount}; } async getUserProfile (userId) { diff --git a/app/views/post/author/all.pug b/app/views/post/author/all.pug index bf42039..15be7d8 100644 --- a/app/views/post/author/all.pug +++ b/app/views/post/author/all.pug @@ -13,4 +13,4 @@ block content li +renderAuthorCredit(author) .uk-card-footer - +renderPaginationBar(`/post/authors`, authors.length ) \ No newline at end of file + +renderPaginationBar(`/post/authors`, totalAuthorCount ) \ No newline at end of file