From 4ff08bd2fbbcb659d58f6b75beee94687b6437a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Sat, 13 Jul 2024 01:22:14 +0200 Subject: [PATCH] instrumentation: Avoid `user.sessionId()` if possible, since it sets a cookie Bug: T289780 Change-Id: I8d80f4e02c6b59087c88d42be671fa81b4d37ba8 --- resources/dist/index.js | Bin 40853 -> 40870 bytes resources/dist/index.js.map.json | Bin 201887 -> 202084 bytes src/instrumentation/statsv.js | 4 ++++ .../node-qunit/instrumentation/statsv.test.js | 16 ++++++++++------ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/resources/dist/index.js b/resources/dist/index.js index a5951087de08a84c94bf868829928f8b0674fd8c..7aec822bed97246e463fdad8bc9f51e33d37c9ef 100644 GIT binary patch delta 32 mcmbQbpJ~~CrVW=T3mVwk+7{K+7=kE!Ma3ek&6g)1;syZLe+;7l delta 14 WcmZ3spK0oTrVW=TZ+IcgJ diff --git a/resources/dist/index.js.map.json b/resources/dist/index.js.map.json index 7a45fe48cae0689b8b089e2e43816646197d0f43..61c3ddf95350ffeeb5224d5257be0884c1c34082 100644 GIT binary patch delta 243 zcmbQglIO`Po()T;={RS&>i9c4mOANpIy&Y!nPfWYxH~#lIzzaQK*}}8$x+AE(cL3x z^7?5yOxn)Pcc-=AoyNHR?lh(zkNT3#GzATXq|)T<)RN4+^q|C&R0UgGTLlA!ni?#^ zh6Pl#i_-`nfZC1DH@szK%)!tf!w5= zR2_xl%)I1Oh0GF#;?$C2g+ztq{QT_9R3(U6MX4pFMR^K}iYN}T21(X#PrJ`#X$k;} CH&zG$ delta 47 zcmV+~0MP&Bstlj046vk@3q@!}EKfl}Pj6{LlhBqd0&PTt{+5USmI1f^mI91Ow=UoU FHZ|`06q*14 diff --git a/src/instrumentation/statsv.js b/src/instrumentation/statsv.js index 38fd5bb28..a1bd041bb 100644 --- a/src/instrumentation/statsv.js +++ b/src/instrumentation/statsv.js @@ -17,6 +17,10 @@ */ export function isEnabled( user, config, experiments ) { const bucketingRate = config.get( 'wgPopupsStatsvSamplingRate', 0 ); + if ( bucketingRate === 0 || bucketingRate === 1 ) { + // Avoid calling user.sessionId() if possible, since it sets a cookie + return !!bucketingRate; + } return experiments.weightedBoolean( 'ext.Popups.statsv', diff --git a/tests/node-qunit/instrumentation/statsv.test.js b/tests/node-qunit/instrumentation/statsv.test.js index b6741e55d..718e823c9 100644 --- a/tests/node-qunit/instrumentation/statsv.test.js +++ b/tests/node-qunit/instrumentation/statsv.test.js @@ -34,11 +34,15 @@ QUnit.test( '#isEnabled', function ( assert ) { config.delete( 'wgPopupsStatsvSamplingRate' ); - isEnabled( user, config, experiments ); - - assert.deepEqual( - weightedBooleanStub.getCall( 1 ).args[ 1 ], - 0, - 'The bucketing rate should be 0 by default.' + const defaultResult = isEnabled( user, config, experiments ); + assert.strictEqual( + defaultResult, + false, + 'The bucketing is disabled by default.' + ); + assert.strictEqual( + weightedBooleanStub.callCount, + 1, + 'The experiments object is not called when bucketing rate is the default 0.' ); } );