From 6312b064f5d54006465268ae3788550d12bc15ea Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 18 Oct 2022 15:38:37 +0530 Subject: [PATCH] Added reset for link click count on edit refs https://github.com/TryGhost/Team/issues/2104 When a newsletter link is edited, we reset its click count to 0 to show only the clicks on newly edited links. This is done by only counting the member click events for a link which are greater than its last updated at, so that all previous click events are not counted for the link, but are included in the total count of all links on the page. --- ghost/core/core/server/models/redirect.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ghost/core/core/server/models/redirect.js b/ghost/core/core/server/models/redirect.js index 7a58e58278..b857c3e1a3 100644 --- a/ghost/core/core/server/models/redirect.js +++ b/ghost/core/core/server/models/redirect.js @@ -53,6 +53,7 @@ const Redirect = ghostBookshelf.Model.extend({ qb.countDistinct('members_click_events.member_id') .from('members_click_events') .whereRaw('redirects.id = members_click_events.redirect_id') + .whereRaw('redirects.updated_at <= members_click_events.created_at') .as('count__clicks'); }); }