Ghost/ghost/admin/app/routes/members.js
Sag 98b51b666d
Fixed ember concurrency cancellation errors (#20324)
fixes https://linear.app/tryghost/issue/SLO-121
fixes https://linear.app/tryghost/issue/SLO-138
fixes https://linear.app/tryghost/issue/SLO-139
fixes https://linear.app/tryghost/issue/SLO-140
fixes https://linear.app/tryghost/issue/SLO-141
fixes https://linear.app/tryghost/issue/SLO-142

- ember-concurrency prevents two executions of the same task from
running at the same time
- when a task is cancelled, the library raises an error by default
- however, we don't need to surface that error as the cancellation of
the second execution is intentional
2024-06-04 16:20:49 +02:00

64 lines
1.8 KiB
JavaScript

import AdminRoute from 'ghost-admin/routes/admin';
import {didCancel} from 'ember-concurrency';
import {inject as service} from '@ember/service';
export default class MembersRoute extends AdminRoute {
@service store;
@service feature;
queryParams = {
label: {refreshModel: true},
searchParam: {refreshModel: true, replace: true},
paidParam: {refreshModel: true},
orderParam: {refreshModel: true},
filterParam: {refreshModel: true},
postAnalytics: {refreshModel: false}
};
beforeModel() {
super.beforeModel(...arguments);
// - TODO: redirect if members is disabled?
}
model(params) {
this.controllerFor('members').resetFilters(params);
return this.controllerFor('members').fetchMembersTask.perform(params);
}
// trigger a background load of members plus labels for filter dropdown
setupController(controller) {
super.setupController(...arguments);
try {
controller.fetchLabelsTask.perform();
} catch (e) {
// Do not throw cancellation errors
if (didCancel(e)) {
return;
}
throw e;
}
}
resetController(controller, _isExiting, transition) {
super.resetController(...arguments);
if (controller.postAnalytics) {
controller.set('postAnalytics', null);
// Only reset filters if we are not going to member route
// Otherwise the filters will be gone if we return
if (!transition?.to?.name?.startsWith('member')) {
controller.set('filterParam', null);
}
}
}
buildRouteInfoMetadata() {
return {
titleToken: 'Members',
mainClasses: ['gh-main-fullwidth']
};
}
}