0
Fork 0
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:
Steve Larson 2024-01-30 15:08:27 -06:00 committed by GitHub
parent f76bb91122
commit d5077ac1bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View file

@ -8,6 +8,7 @@ export default class GhMembersNoMembersComponent extends Component {
@service store;
@service notifications;
@service settings;
@service membersCountCache;
@action
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;
} catch (error) {
if (error) {

View file

@ -15,6 +15,7 @@ export default class MemberController extends Controller {
@service session;
@service dropdown;
@service membersStats;
@service membersCountCache;
@service modals;
@service notifications;
@service router;
@ -139,6 +140,7 @@ export default class MemberController extends Controller {
afterDelete: () => {
this.membersStats.invalidate();
this.members.refreshData();
this.membersCountCache.clear();
this.transitionToRoute('members');
}
});
@ -181,12 +183,18 @@ export default class MemberController extends Controller {
Object.assign(member, scratchProps);
try {
const clearCountCache = member.isNew; // clear cache for adding new members so the count is updated without waiting for a refresh
yield member.save();
member.updateLabels();
this.members.refreshData();
this.setInitialRelationshipValues();
if (clearCountCache) {
this.membersCountCache.clear();
}
// replace 'member.new' route with 'member' route
this.replaceRoute('member', member);

View file

@ -618,11 +618,6 @@ test.describe('Updating post access', () => {
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
await createPostDraft(page, {title: 'Published in timezones', body: 'Published in timezones'});
await page.locator('[data-test-button="publish-flow"]').first().click();