Ghost/ghost/members-events-service
Chris Raible 971d497c1e
Added caching to LastSeenAtUpdater (#20964)
ref
https://linear.app/tryghost/issue/ENG-1543/debounce-the-members-lastseenatupdater

- The `LastSeenAtUpdater.updateLastSeenAt` function is called in
response to a `MemberClickEvent` — when a member clicks a link in an
email with tracking enabled. This function can be called many times for
the same member in a short period of time if e.g. a link checker is
clicking all the links in an email they received.
- This function should only update a member's `last_seen_at` timestamp
once per day. To accomplish this, `updateLastSeenAt` runs a
`select...for update` query to find the member's current `last_seen_at`
timestamp, and only updates the timestamp if the current `last_seen_at`
is before the start of the current day. The `for update` is required to
avoid a race condition, which previously caused this function to update
the `last_seen_at` timestamp more frequently than needed, which results
in many unnecessary database queries. However, we still run the initial
`select...for update` query for each event, which seems to be resulting
in contention for locks on the member's row in the `members` table.
- This commit introduces a simple in-memory cache so that we avoid
calling `updateLastSeenAt` if the member's `last_seen_at` timestamp has
already been updated in the current day, which should avoid running so
many `select...for update` queries and locking the `members` table up.
2024-09-13 00:54:43 -07:00
..
lib Added caching to LastSeenAtUpdater (#20964) 2024-09-13 00:54:43 -07:00
test Added caching to LastSeenAtUpdater (#20964) 2024-09-13 00:54:43 -07:00
.eslintrc.js Added the members-events-service package 2022-02-28 14:42:17 +01:00
index.js Added the members-events-service package 2022-02-28 14:42:17 +01:00
package.json Update TryGhost packages 2024-08-05 12:12:34 +02:00