Removed duplicate member count queries in admin (#19473)

no refs
- member_count endpoint was queried multiple times on load
- moved to collectively use the member stats service
- prevented multiple tasks from being queued up to return count
This commit is contained in:
Steve Larson 2024-01-13 18:40:28 +01:00 committed by GitHub
parent be6b9e437f
commit e27a5c1e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -85,6 +85,7 @@ export default class DashboardStatsService extends Service {
@service membersCountCache;
@service settings;
@service membersUtils;
@service membersStats;
/**
* @type {?SiteStatus} Contains information on what graphs need to be shown
@ -524,8 +525,7 @@ export default class DashboardStatsService extends Service {
return;
}
let statsUrl = this.ghostPaths.url.api('stats/member_count');
let stats = yield this.ajax.request(statsUrl);
const stats = yield this.membersStats.fetchMemberCounts();
this.memberCountStats = stats.stats.map((d) => {
return {
...d,

View File

@ -52,9 +52,13 @@ export default class MembersStatsService extends Service {
}
fetchMemberCount() {
let staleData = this._lastFetchedMemberCounts && (new Date() - this._lastFetchedMemberCounts) > ONE_MINUTE;
// if already running, return existing promise
if (this._fetchMemberCountsTask.isRunning) {
return this._fetchMemberCountsTask.last;
}
// return existing stats unless data is > 1 min old
let staleData = this._lastFetchedMemberCounts && (new Date() - this._lastFetchedMemberCounts) > ONE_MINUTE;
if (this.totalMemberCount && !this._forceRefresh && !staleData && this._fetchMemberCountsTask.last) {
return this._fetchMemberCountsTask.last;
}