0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/core/server/models
Kevin Ansfield d34a3263e8 Store email batch and recipient records when sending newsletters (#12195)
requires https://github.com/TryGhost/Ghost/pull/12192

- added initial `EmailBatch` and `EmailRecipient` model definitions with defaults and relationships
- added missing `post` relationship function to email model
- fetch member list without bookshelf
    - bookshelf can add around 3x overhead when fetching the members list for an email
    - we don't need full members at this point, only having the data is fine
    - if we need full models later on we can push the model hydration into background jobs where recipient batches are fetched ready for an email to be sent
    - bookshelf model instantiation of many models blocks the event loop, using knex directly keeps concurrent requests fast
    - adds `getFilteredCollectionQuery` method to base model to facilitate getting a knex query based on our normal model filters along with transaction/forUpdate applied
- store recipient list before sending email
    - chunk already-fetched members list into batches and insert records into the `email_recipients` table via knex
    - chunked into batches of 1000 to match the number of emails that Mailgun accepts in a single API request but this may not be the absolute fastest batch size for recipient insertion:
        | Batch size | Batch time | Total time |
        | ---------- | ---------- | ---------- |
        |        500 |       20ms |     4142ms |
        |       1000 |       50ms |     4651ms |
        |       5000 |      170ms |     3540ms |
        |      10000 |      370ms |     3684ms |
    - create an email_batch record before inserting recipient rows so we can effeciently fetch recipients by batch and store the overall batch status
2020-09-29 17:17:54 +01:00
..
base Store email batch and recipient records when sending newsletters (#12195) 2020-09-29 17:17:54 +01:00
plugins Added support for ordering Post API resources by fields coming form posts_meta table (#12226) 2020-09-24 13:32:40 +12:00
relations Extracted promise libs and history into @tryghost/promise 2020-08-11 18:44:21 +01:00
action.js
api-key.js Moved core/server/lib/common/logging to core/shared/logging (#11857) 2020-05-28 19:30:23 +01:00
author.js
email-batch.js Store email batch and recipient records when sending newsletters (#12195) 2020-09-29 17:17:54 +01:00
email-recipient.js Store email batch and recipient records when sending newsletters (#12195) 2020-09-29 17:17:54 +01:00
email.js Store email batch and recipient records when sending newsletters (#12195) 2020-09-29 17:17:54 +01:00
index.js Store email batch and recipient records when sending newsletters (#12195) 2020-09-29 17:17:54 +01:00
integration.js
invite.js Extracted core/server/lib/security to @tryghost/security package 2020-08-11 14:06:50 +01:00
label.js Refactored common lib import to use destructuring (#11835) 2020-05-22 19:22:20 +01:00
member-stripe-customer.js Added error handling for failed member imports 2020-08-26 17:11:35 +12:00
member.js 🐛 Fixed incorrect status used for trial subscription query 2020-09-02 13:07:48 +01:00
mobiledoc-revision.js
permission.js
post.js Added support for ordering Post API resources by fields coming form posts_meta table (#12226) 2020-09-24 13:32:40 +12:00
posts-meta.js Moved core/server/lib/url-utils to core/shared/url-utils (#11856) 2020-05-28 11:57:02 +01:00
role.js Refactored common lib import to use destructuring (#11835) 2020-05-22 19:22:20 +01:00
session.js
settings.js 🐛 Fixed importing Stripe Plans with amount 0 (#12062) 2020-07-20 14:59:23 +02:00
single-use-token.js Added SingleUseToken model (#12215) 2020-09-18 15:05:56 +01:00
stripe-customer-subscription.js Added error handling for failed member imports 2020-08-26 17:11:35 +12:00
tag-public.js
tag.js Refactored common lib import to use destructuring (#11835) 2020-05-22 19:22:20 +01:00
user.js Extracted promise libs and history into @tryghost/promise 2020-08-11 18:44:21 +01:00
webhook.js