From 926d8911e153573337403d5896b209e457cf5023 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Fri, 22 Sep 2023 12:35:26 +0200 Subject: [PATCH] Merge pull request #14913 from overleaf/jpa-no-cache-for-anon [web] purge split test cache for anonymous users GitOrigin-RevId: e268b30ac03d4cab0f7976657089c58bc3c84210 --- .../app/src/Features/SplitTests/SplitTestHandler.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/web/app/src/Features/SplitTests/SplitTestHandler.js b/services/web/app/src/Features/SplitTests/SplitTestHandler.js index cb58acba15..fabce8b25b 100644 --- a/services/web/app/src/Features/SplitTests/SplitTestHandler.js +++ b/services/web/app/src/Features/SplitTests/SplitTestHandler.js @@ -248,7 +248,15 @@ async function _getAssignment( return DEFAULT_ASSIGNMENT } - if (session) { + // Do not cache assignments for anonymous users. All the context for their assignments is in the session: + // They cannot be part of the alpha or beta program, and they will use their analyticsId for assignments. + const canUseSessionCache = session && SessionManager.isUserLoggedIn(session) + if (session && !canUseSessionCache) { + // Purge the existing cache + delete session.cachedSplitTestAssignments + } + + if (canUseSessionCache) { const cachedVariant = _getCachedVariantFromSession( session, splitTest.name, @@ -275,7 +283,7 @@ async function _getAssignment( user = user || (userId && (await _getUser(userId, splitTestName))) const { activeForUser, selectedVariantName, phase, versionNumber } = await _getAssignmentMetadata(analyticsId, user, splitTest) - if (session) { + if (canUseSessionCache) { _setVariantInSession({ session, splitTestName,