mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 10:42:45 +03:00
971d497c1e
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. |
||
---|---|---|
.. | ||
lib | ||
test | ||
.eslintrc.js | ||
index.js | ||
package.json |