From 9d9c14f01613f3ee14df75daf4b9cdb1f251af1f Mon Sep 17 00:00:00 2001 From: Ivan Ukhov Date: Tue, 11 Feb 2020 11:39:34 +0100 Subject: [PATCH] Take the reason and user into account when caching events --- src/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index adbb569..c9a0bab 100644 --- a/src/index.js +++ b/src/index.js @@ -145,9 +145,8 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef function sendFlagEvent(key, detail, defaultValue, includeReason) { const user = ident.getUser(); const now = new Date(); - const value = detail ? detail.value : null; if (!options.allowFrequentDuplicateEvents) { - const cacheKey = JSON.stringify(value) + (user && user.key ? user.key : '') + key; // see below + const cacheKey = JSON.stringify(detail) + JSON.stringify(user) + key; // see below const cached = seenRequests[cacheKey]; // cache TTL is five minutes if (cached && now - cached < 300000) { @@ -160,7 +159,7 @@ export function initialize(env, user, specifiedOptions, platform, extraOptionDef kind: 'feature', key: key, user: user, - value: value, + value: detail ? detail.value : null, variation: detail ? detail.variationIndex : null, default: defaultValue, creationDate: now.getTime(),