Ghost/ghost/admin/app/helpers/members-count-fetcher.js
Kevin Ansfield 7c4674507e Switched members-count-fetcher to use members-count-cache
no issue

In the new publish flow we use `{{members-count-fetcher}}` to show member counts as needed in the template without needing to worry about manually fetching counts in the backing classes. However, when switching between states in the flow the count would be re-requested resulting in some glitchy looking async count rendering. By changing `{{members-count-fetcher}}` to use our `members-count-cache` service internally we reduce the likelihood of an async count being triggered when switching between publish flow states.

- updated `members-count-cache` service methods to work with filter strings or full query objects
- switched `members-count-fetcher` resource to use `members-count-cache` in place of directly querying the store
2022-05-05 11:18:49 +01:00

40 lines
1.1 KiB
JavaScript

import {Resource} from 'ember-could-get-used-to-this';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
import {tracked} from '@glimmer/tracking';
export default class MembersCount extends Resource {
@service membersCountCache;
@tracked count = null;
get value() {
return {
isLoading: this.fetchMembersTask.isRunning,
count: this.count
};
}
setup() {
const query = this.args.named.query || {};
this._query = query;
this.fetchMembersTask.perform({query});
}
update() {
// required due to a weird invalidation issue when using Ember Data with ember-could-get-used-to-this
// TODO: re-test after upgrading to ember-resources
if (this.args.named.query !== this._query) {
const query = this.args.named.query || {};
this._query = query;
this.fetchMembersTask.perform({query});
}
}
@task
*fetchMembersTask({query} = {}) {
const count = yield this.membersCountCache.count(query);
this.count = count;
}
}