🐛 Fixed slow loading and high memory usage of members list screen

refs https://github.com/TryGhost/Team/issues/1423

- problem:
  - all members requests were automatically adding `?include=email_recipients` as the email recipients relationship was set up to be always embedded
  - embedded email_recipient records also embed the whole email record
  - on the members index screen this meant for each of the 50 members loaded on a page we were also loading every email they have ever received resulting in a huge API response
  - this was not a problem previously because the API was ignoring the `include` parameter on the browse endpoint and Admin wasn't formatting the include properly in snake_case
- solution:
  - the only place we need associated email recipients is on the member details screen where they are used to show the email activity feed
  - removing the `{embedded: 'always'}` option for the `member.emailRecipients` association stops `?include=email_recipients` being added automatically to every members request
  - the member details screen explicitly adds `?include=email_recipients` so no further changes are needed
  - activity feed will be changing to use proper event objects in the future and further optimisation can be made
This commit is contained in:
Kevin Ansfield 2022-03-15 18:26:24 +00:00 committed by Matt Hanley
parent 042538ba2d
commit 129d202595
2 changed files with 5 additions and 1 deletions

View File

@ -23,7 +23,7 @@ export default Model.extend(ValidationEngine, {
products: attr('member-product'),
labels: hasMany('label', {embedded: 'always', async: false}),
emailRecipients: hasMany('emailRecipient', {embedded: 'always', async: false}),
emailRecipients: hasMany('emailRecipient', {async: true}),
ghostPaths: service(),
ajax: service(),

View File

@ -63,6 +63,10 @@ describe('Acceptance: Members', function () {
expect(member.querySelector('.gh-members-list-name').textContent, 'member list item title')
.to.equal(member1.name);
// it does not add ?include=email_recipients
const membersRequests = this.server.pretender.handledRequests.filter(r => r.url.match(/\/members\/(\?|$)/));
expect(membersRequests[0].url).to.not.have.string('email_recipients');
await visit(`/members/${member1.id}`);
// // second wait is needed for the member details to settle