mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Reduced amount of member count queries when opening the editor (#19474)
no issue When we open the editor, we fire 4 requests to fetch member counts. This commit fixes this by replacing those calls with the members count cache service.
This commit is contained in:
parent
2c4052b332
commit
1f2857e0e4
4 changed files with 12 additions and 11 deletions
|
@ -6,6 +6,7 @@ import {tracked} from '@glimmer/tracking';
|
||||||
export default class GhMembersSegmentCountComponent extends Component {
|
export default class GhMembersSegmentCountComponent extends Component {
|
||||||
@service store;
|
@service store;
|
||||||
@service session;
|
@service session;
|
||||||
|
@service membersCountCache;
|
||||||
|
|
||||||
@tracked total = 0;
|
@tracked total = 0;
|
||||||
@tracked segmentTotal = 0;
|
@tracked segmentTotal = 0;
|
||||||
|
@ -17,9 +18,7 @@ export default class GhMembersSegmentCountComponent extends Component {
|
||||||
this.fetchSegmentTotalTask.perform();
|
this.fetchSegmentTotalTask.perform();
|
||||||
|
|
||||||
const filter = this.args.enforcedFilter || undefined;
|
const filter = this.args.enforcedFilter || undefined;
|
||||||
|
this.total = yield this.membersCountCache.count({filter});
|
||||||
const members = yield this.store.query('member', {limit: 1, filter});
|
|
||||||
this.total = members.meta.pagination.total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@task({group: 'fetchTasks'})
|
@task({group: 'fetchTasks'})
|
||||||
|
|
|
@ -9,6 +9,7 @@ export default class PublishOptionsResource extends Resource {
|
||||||
@service session;
|
@service session;
|
||||||
@service settings;
|
@service settings;
|
||||||
@service store;
|
@service store;
|
||||||
|
@service membersCountCache;
|
||||||
|
|
||||||
@inject config;
|
@inject config;
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ export default class PublishOptionsResource extends Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
_createPublishOptions(post) {
|
_createPublishOptions(post) {
|
||||||
const {config, limit, settings, store} = this;
|
const {config, limit, settings, store, membersCountCache} = this;
|
||||||
|
|
||||||
return new PublishOptions({
|
return new PublishOptions({
|
||||||
config,
|
config,
|
||||||
|
@ -43,6 +44,7 @@ export default class PublishOptionsResource extends Resource {
|
||||||
post,
|
post,
|
||||||
settings,
|
settings,
|
||||||
store,
|
store,
|
||||||
|
membersCountCache,
|
||||||
user: this.session.user
|
user: this.session.user
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ class HostLimitError extends LimitError {
|
||||||
export default class LimitsService extends Service {
|
export default class LimitsService extends Service {
|
||||||
@service store;
|
@service store;
|
||||||
@service membersStats;
|
@service membersStats;
|
||||||
|
@service membersCountCache;
|
||||||
|
|
||||||
@inject config;
|
@inject config;
|
||||||
|
|
||||||
|
@ -93,10 +94,7 @@ export default class LimitsService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMembersCount() {
|
async getMembersCount() {
|
||||||
const members = await this.store.query('member', {limit: 1});
|
return this.membersCountCache.count({});
|
||||||
const total = members.meta.pagination.total;
|
|
||||||
|
|
||||||
return total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNewslettersCount() {
|
async getNewslettersCount() {
|
||||||
|
|
|
@ -10,6 +10,7 @@ export default class PublishOptions {
|
||||||
limit = null;
|
limit = null;
|
||||||
settings = null;
|
settings = null;
|
||||||
store = null;
|
store = null;
|
||||||
|
membersCountCache = null;
|
||||||
|
|
||||||
// passed in models
|
// passed in models
|
||||||
post = null;
|
post = null;
|
||||||
|
@ -234,13 +235,14 @@ export default class PublishOptions {
|
||||||
|
|
||||||
// setup -------------------------------------------------------------------
|
// setup -------------------------------------------------------------------
|
||||||
|
|
||||||
constructor({config, limit, post, settings, store, user} = {}) {
|
constructor({config, limit, post, settings, store, user, membersCountCache} = {}) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
this.post = post;
|
this.post = post;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.store = store;
|
this.store = store;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
this.membersCountCache = membersCountCache;
|
||||||
|
|
||||||
// this needs to be set here rather than a class-level property because
|
// this needs to be set here rather than a class-level property because
|
||||||
// unlike Ember-based classes the services are not injected so can't be
|
// unlike Ember-based classes the services are not injected so can't be
|
||||||
|
@ -285,8 +287,8 @@ export default class PublishOptions {
|
||||||
// Only Admins/Owners have permission to browse members and get a count
|
// Only Admins/Owners have permission to browse members and get a count
|
||||||
// for Editors/Authors set member count to 1 so email isn't disabled for not having any members
|
// for Editors/Authors set member count to 1 so email isn't disabled for not having any members
|
||||||
if (this.user.isAdmin) {
|
if (this.user.isAdmin) {
|
||||||
promises.push(this.store.query('member', {limit: 1}).then((res) => {
|
promises.push(this.membersCountCache.count({}).then((res) => {
|
||||||
this.totalMemberCount = res.meta.pagination.total;
|
this.totalMemberCount = res;
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
this.totalMemberCount = 1;
|
this.totalMemberCount = 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue