mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
🐛 Fixed incorrect member count on sidebar (#15330)
refshttps://github.com/TryGhost/Team/issues/1738 - Changed sidebar member count to use new API endpoint data. - Added separate function for getting member count. - changed `_fetchCountsTask` to use new `/stats/member_count/` endpoint - updated @task to calculate total members from endpoint data.
This commit is contained in:
parent
d0c45cbe9e
commit
dac3fff90f
@ -110,12 +110,12 @@ export default class Main extends Component.extend(ShortcutsMixin) {
|
||||
@task(function* () {
|
||||
try {
|
||||
this.set('memberCountLoading', true);
|
||||
const stats = yield this.membersStats.fetchCounts();
|
||||
const stats = yield this.membersStats.fetchMemberCount();
|
||||
this.set('memberCountLoading', false);
|
||||
if (stats) {
|
||||
const statsDateObj = this.membersStats.fillCountDates(stats.data) || {};
|
||||
const dateValues = Object.values(statsDateObj);
|
||||
this.set('memberCount', dateValues.length ? dateValues[dateValues.length - 1].total : 0);
|
||||
const {free, paid, comped} = stats.meta.totals;
|
||||
const total = free + paid + comped || 0;
|
||||
this.set('memberCount', total);
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
@ -16,6 +16,7 @@ export default class MembersStatsService extends Service {
|
||||
@tracked countStats = null;
|
||||
@tracked mrrStats = null;
|
||||
@tracked newsletterStats = null;
|
||||
@tracked totalMemberCount = null;
|
||||
|
||||
fetch() {
|
||||
let daysChanged = this._lastFetchedDays !== this.days;
|
||||
@ -50,6 +51,22 @@ export default class MembersStatsService extends Service {
|
||||
return this._fetchCountsTask.perform();
|
||||
}
|
||||
|
||||
fetchMemberCount() {
|
||||
let staleData = this._lastFetchedMemberCounts && (new Date() - this._lastFetchedMemberCounts) > ONE_MINUTE;
|
||||
|
||||
// return an already in-progress promise unless params have changed
|
||||
if (this._fetchMemberCountsTask.isRunning) {
|
||||
return this._fetchMemberCountsTask.last;
|
||||
}
|
||||
|
||||
// return existing stats unless data is > 1 min old
|
||||
if (this.totalMemberCount && !this._forceRefresh && !staleData) {
|
||||
return Promise.resolve(this.totalMemberCount);
|
||||
}
|
||||
|
||||
return this._fetchMemberCountsTask.perform();
|
||||
}
|
||||
|
||||
fetchNewsletterStats() {
|
||||
let staleData = this._lastFetchedNewsletterStats && (new Date() - this._lastFetchedNewsletterStats) > ONE_MINUTE;
|
||||
|
||||
@ -196,6 +213,16 @@ export default class MembersStatsService extends Service {
|
||||
return stats;
|
||||
}
|
||||
|
||||
@task
|
||||
*_fetchMemberCountsTask() {
|
||||
this._lastFetchedMemberCounts = new Date();
|
||||
|
||||
let statsUrl = this.ghostPaths.url.api('stats/member_count/');
|
||||
let stats = yield this.ajax.request(statsUrl);
|
||||
this.totalMemberCount = stats;
|
||||
return stats;
|
||||
}
|
||||
|
||||
@task
|
||||
*_fetchMRRTask() {
|
||||
this._lastFetchedMRR = new Date();
|
||||
|
Loading…
Reference in New Issue
Block a user