Replaced menu members count stats API with members count cache (#19476)

no issue

The members stats API is a lot more slower than the normal members count
cache, and we use the members count cache in a lot more places. So we
can cache it more.
This commit is contained in:
Simon Backx 2024-01-13 20:05:29 +01:00 committed by GitHub
parent 1f2857e0e4
commit d468563feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 23 deletions

View File

@ -100,15 +100,19 @@
<li class="relative">
{{#if (eq this.router.currentRouteName "members.index")}}
<LinkTo @route="members" @current-when="members member member.new" @query={{reset-query-params "members.index"}} data-test-nav="members">{{svg-jar "members"}}Members
{{#unless this.memberCountLoading}}
<span class="gh-nav-member-count">{{format-number this.membersStats.memberCount}}</span>
{{/unless}}
{{#let (members-count-fetcher) as |count|}}
{{#unless count.isLoading}}
<span class="gh-nav-member-count">{{format-number count.count}}</span>
{{/unless}}
{{/let}}
</LinkTo>
{{else}}
<LinkTo @route="members" @current-when="members member member.new" data-test-nav="members">{{svg-jar "members"}}Members
{{#unless this.memberCountLoading}}
<span class="gh-nav-member-count">{{format-number this.membersStats.memberCount}}</span>
{{/unless}}
{{#let (members-count-fetcher) as |count|}}
{{#unless count.isLoading}}
<span class="gh-nav-member-count">{{format-number count.count}}</span>
{{/unless}}
{{/let}}
</LinkTo>
{{/if}}
</li>

View File

@ -10,7 +10,6 @@ import {htmlSafe} from '@ember/template';
import {inject} from 'ghost-admin/decorators/inject';
import {inject as service} from '@ember/service';
import {tagName} from '@ember-decorators/component';
import {task} from 'ember-concurrency';
@classic
@tagName('')
@ -33,7 +32,6 @@ export default class Main extends Component.extend(ShortcutsMixin) {
iconStyle = '';
iconClass = '';
memberCountLoading = true;
shortcuts = null;
@match('router.currentRouteName', /^settings\.integration/)
@ -69,10 +67,6 @@ export default class Main extends Component.extend(ShortcutsMixin) {
didReceiveAttrs() {
super.didReceiveAttrs(...arguments);
this._setIconStyle();
if (this.session.user && this.session.user.isAdmin) {
this._loadMemberCountsTask.perform();
}
}
didInsertElement() {
@ -114,17 +108,6 @@ export default class Main extends Component.extend(ShortcutsMixin) {
this.explore.openExploreWindow();
}
@task(function* () {
try {
this.set('memberCountLoading', true);
yield this.membersStats.fetchMemberCount();
this.set('memberCountLoading', false);
} catch (e) {
return false;
}
})
_loadMemberCountsTask;
_setIconStyle() {
let icon = this.icon;