mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Cleared member count cache on manual member add/delete (#19623)
refs https://linear.app/tryghost/issue/ENG-599 - member count is based on the cache which only updates ~every minute - forced cache clear on manual member add/delete (not import) - tests were failing based on the assumption that a new site that adds a member has a nonzero member count, although the cache did not reflect this quickly enough for the test to pass Previously on a new site if you tried to publish a newsletter, it would require at least one member. If you quickly added a member and tried to send a newsletter, it would stop you saying you need at least one member, requiring a browser refresh. This was a bug that is resolved with this changes, as well as odd behaviour to try to write tests around.
This commit is contained in:
parent
f76bb91122
commit
d5077ac1bf
3 changed files with 12 additions and 5 deletions
|
@ -8,6 +8,7 @@ export default class GhMembersNoMembersComponent extends Component {
|
||||||
@service store;
|
@service store;
|
||||||
@service notifications;
|
@service notifications;
|
||||||
@service settings;
|
@service settings;
|
||||||
|
@service membersCountCache;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
addYourself() {
|
addYourself() {
|
||||||
|
@ -38,6 +39,9 @@ export default class GhMembersNoMembersComponent extends Component {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// force update the member count; this otherwise only updates every minute
|
||||||
|
yield this.membersCountCache.count({});
|
||||||
|
|
||||||
return member;
|
return member;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ export default class MemberController extends Controller {
|
||||||
@service session;
|
@service session;
|
||||||
@service dropdown;
|
@service dropdown;
|
||||||
@service membersStats;
|
@service membersStats;
|
||||||
|
@service membersCountCache;
|
||||||
@service modals;
|
@service modals;
|
||||||
@service notifications;
|
@service notifications;
|
||||||
@service router;
|
@service router;
|
||||||
|
@ -139,6 +140,7 @@ export default class MemberController extends Controller {
|
||||||
afterDelete: () => {
|
afterDelete: () => {
|
||||||
this.membersStats.invalidate();
|
this.membersStats.invalidate();
|
||||||
this.members.refreshData();
|
this.members.refreshData();
|
||||||
|
this.membersCountCache.clear();
|
||||||
this.transitionToRoute('members');
|
this.transitionToRoute('members');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -181,12 +183,18 @@ export default class MemberController extends Controller {
|
||||||
Object.assign(member, scratchProps);
|
Object.assign(member, scratchProps);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const clearCountCache = member.isNew; // clear cache for adding new members so the count is updated without waiting for a refresh
|
||||||
|
|
||||||
yield member.save();
|
yield member.save();
|
||||||
member.updateLabels();
|
member.updateLabels();
|
||||||
this.members.refreshData();
|
this.members.refreshData();
|
||||||
|
|
||||||
this.setInitialRelationshipValues();
|
this.setInitialRelationshipValues();
|
||||||
|
|
||||||
|
if (clearCountCache) {
|
||||||
|
this.membersCountCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
// replace 'member.new' route with 'member' route
|
// replace 'member.new' route with 'member' route
|
||||||
this.replaceRoute('member', member);
|
this.replaceRoute('member', member);
|
||||||
|
|
||||||
|
|
|
@ -618,11 +618,6 @@ test.describe('Updating post access', () => {
|
||||||
email: 'test@recipient.com'
|
email: 'test@recipient.com'
|
||||||
});
|
});
|
||||||
|
|
||||||
// NOTE: without the refresh, this test cannot be run in isolation because the member count (cache) isn't updated quickly enough, making the button to publish+send disabled (because there are no members)
|
|
||||||
// this also means that any retries will fail
|
|
||||||
// the reason is sometimes works is because the member count will carry over from previous tests via recycling the browser session, such that the cache count is >0
|
|
||||||
await page.reload();
|
|
||||||
|
|
||||||
// go to publish a post
|
// go to publish a post
|
||||||
await createPostDraft(page, {title: 'Published in timezones', body: 'Published in timezones'});
|
await createPostDraft(page, {title: 'Published in timezones', body: 'Published in timezones'});
|
||||||
await page.locator('[data-test-button="publish-flow"]').first().click();
|
await page.locator('[data-test-button="publish-flow"]').first().click();
|
||||||
|
|
Loading…
Add table
Reference in a new issue