Ghost/ghost/core/test/unit/server/services
Chris Raible dcd65bfa4f
Added caching to the LinkRedirectRepository (#20036)
ref
https://linear.app/tryghost/issue/ENG-851/implement-a-minimal-but-complete-version-of-redirect-caching-to
ref https://app.incident.io/ghost/incidents/55

Often immediately after sending an email, sites receive a large volume
of requests to LinkRedirect endpoints from members clicking on the links in
the email.

We currently don't cache any of these requests in our CDN, because we
also record click events, update the member's `last_seen_at` timestamp,
and send webhooks in response to these clicks, so Ghost needs to handle
each of these requests itself. This means that each of these LinkRedirect requests
hits Ghost, and currently all these requests hit the database to lookup
where to redirect the member to.

Each one of these requests can make up to 11 database queries, which can
quickly exhaust Ghost's database connection pool. Even though the
LinkRedirect lookup query is fairly cheap and quick, these queries aren't
prioritized over the "record" queries Ghost needs to handle, so they can
get stuck behind other queries in the queue and eventually timeout.

The result is that members are unable to actually reach the destination
of the link they clicked on, instead receiving a 500 error in Ghost, or
it can take a long time (60s+) for the redirect to happen.

This PR uses our existing `adapterManager` to cache the redirect lookups
either in-memory or in Redis (if configured — by default there is no caching). This only removes 1 out of
11 queries per redirect request, so it won't reduce the load on the DB
drastically, but it at least decouples the serving of the LinkRedirect from
the DB so the member can be redirected even if the DB is under heavy
load.

Local load testing results have shown a decrease in response times from
60 seconds to ~50ms for the redirect requests when handling 500 requests
per second, and reduced the 500 error rate to 0.
2024-04-25 19:17:25 -07:00
..
adapter-manager Added JSDoc to adapter options resolver 2022-09-06 17:51:57 +08:00
api-version-compatibility Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
auth Added eslint rule for file naming convention 2023-05-09 12:34:34 -04:00
collections Removed unused collections repositories 2023-07-14 14:20:37 +08:00
custom-redirects Fixed test on Node 20 2024-04-18 13:17:16 +02:00
frontend-data-service Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
link-redirection Added caching to the LinkRedirectRepository (#20036) 2024-04-25 19:17:25 -07:00
link-tracking Added endpoint for fixing newsletter links 2022-10-20 17:50:02 +05:30
mail Added email address alignment protections (#19094) 2023-11-23 10:25:30 +01:00
mail-events Add endpoint to record mail events (#16990) 2023-06-23 12:22:01 +01:00
members 🐛 Fixed unsubscribe button requiring manual action + wrong confirmation 2023-11-08 15:05:47 +01:00
mentions Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
milestones Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
newsletters Fixed clearing invalid sender_email when changing newsletter sender_reply_to (#19555) 2024-01-23 16:10:11 +01:00
notifications Added eslint rule for file naming convention 2023-05-09 12:34:34 -04:00
oembed Support twitter embeds using x as host (#18550) 2023-10-09 15:55:26 -05:00
permissions Removed support for id specific permissions 2024-03-21 00:21:40 +07:00
public-config Updated Sentry env to use PRO_ENV when available (#19441) 2024-01-05 12:10:39 +00:00
route-settings Enforced more Mocha lint rules (#19720) 2024-04-16 09:37:06 +02:00
settings Improved sending email addresses for self-hosters (#19617) 2024-01-30 11:21:08 +01:00
settings-helpers Added eslint rule for file naming convention 2023-05-09 12:34:34 -04:00
slack-notifications Added ability to pass minThreshold for Milestone Slack notifications 2024-03-14 12:06:43 -04:00
staff Moved Milestone emails to GA 2023-03-23 17:35:23 +00:00
stripe Fixed configUtils and adapter cache issues in E2E tests (#16167) 2023-01-30 14:06:20 +01:00
themes Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
tiers Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
url Enforced more Mocha lint rules (#19720) 2024-04-16 09:37:06 +02:00
users Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
webhooks Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
limits.test.js Updated to use assert/strict everywhere (#17047) 2023-06-21 09:56:59 +01:00
slack.test.js Prevented registering multiple Slack event listeners 2023-06-12 15:04:11 +02:00
xmlrpc.test.js Prevent xmlprc tests from outputting errors for failure cases 2023-02-28 11:14:11 +00:00