From 16d0629de3f383df889fe1aafe2ab3d636b5f13c Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Mon, 28 Mar 2022 09:54:21 +0200 Subject: [PATCH] Added last seen and member count stats from real API in dashboard 5 refs https://github.com/TryGhost/Team/issues/1443 --- ghost/admin/app/services/dashboard-stats.js | 36 ++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/ghost/admin/app/services/dashboard-stats.js b/ghost/admin/app/services/dashboard-stats.js index 4a65b1ad19..7ac58c7540 100644 --- a/ghost/admin/app/services/dashboard-stats.js +++ b/ghost/admin/app/services/dashboard-stats.js @@ -178,8 +178,19 @@ export default class DashboardStatsService extends Service { this.memberCounts = {...this.dashboardMocks.memberCounts}; return; } - // Normal implementation - // @todo + + // @todo We need to have way to reduce the total number of API requests + const paidResult = yield this.store.query('member', {limit: 1, filter: 'status:paid'}); + const paid = paidResult.meta.pagination.total; + + const freeResult = yield this.store.query('member', {limit: 1, filter: 'status:-paid'}); + const free = freeResult.meta.pagination.total; + + this.memberCounts = { + total: paid + free, + paid, + free + }; } loadMemberCountStats() { @@ -257,8 +268,25 @@ export default class DashboardStatsService extends Service { this.membersLastSeen7d = this.dashboardMocks.membersLastSeen7d; return; } - // Normal implementation - // @todo + + // @todo We need to have way to reduce the total number of API requests + + const start30d = new Date(Date.now() - 30 * 3600 * 1000); + const start7d = new Date(Date.now() - 7 * 3600 * 1000); + + let extraFilter = ''; + if (this.lastSeenFilterStatus === 'paid') { + extraFilter = '+status:paid'; + } else if (this.lastSeenFilterStatus === 'free') { + extraFilter = '+status:-paid'; + } + + // todo: filter by status here + const result30d = yield this.store.query('member', {limit: 1, filter: 'last_seen_at:>' + start30d.toISOString() + extraFilter}); + this.membersLastSeen30d = result30d.meta.pagination.total; + + const result7d = yield this.store.query('member', {limit: 1, filter: 'last_seen_at:>' + start7d.toISOString() + extraFilter}); + this.membersLastSeen7d = result7d.meta.pagination.total; } loadPaidMembersByCadence() {