AndyRussG has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/201349

Change subject: Check choiceData for staleness
......................................................................

Check choiceData for staleness

There may be caching issues that we can't control that cause
some users to get stale choiceData. Here we test for by checking
if we got any campaings that should have ended, and turn off
campaigns completely if we find it.

Bug: T88276
Change-Id: Ib0f2ede85083d9568190f0211bd80f68e745f171
---
M modules/ext.centralNotice.bannerController/bannerController.lib.js
1 file changed, 35 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/49/201349/1

diff --git a/modules/ext.centralNotice.bannerController/bannerController.lib.js 
b/modules/ext.centralNotice.bannerController/bannerController.lib.js
index 84d9e08..fd664a6 100644
--- a/modules/ext.centralNotice.bannerController/bannerController.lib.js
+++ b/modules/ext.centralNotice.bannerController/bannerController.lib.js
@@ -8,6 +8,7 @@
        mw.cnBannerControllerLib = {
 
                BUCKET_COOKIE_NAME: 'centralnotice_buckets_by_campaign',
+               CAMPAIGN_STALENESS_LEEWAY: 15, // Minutes leeway for checking 
stale choice data
 
                choiceData: null,
                bucketsByCampaign: null,
@@ -217,18 +218,49 @@
                /**
                 * Filter choiceData on the user's country, logged-in status 
and device.
                 * Campaigns that don't target the user's country or have no 
banners for
-                * their logged-in status and device will be removed. We 
operate on
-                * this.choiceData.
+                * their logged-in status and device will be removed.
+                *
+                * We also check for campaigns that are not currently active, 
which might
+                * happen due to incorrect caching of choiceData between us and 
the user.
+                * If that happens we just toss everything out because one 
stale campaign
+                * spoils the basket. TODO: Log when this happens.
+                *
+                * We operate on this.choiceData.
                 */
                filterChoiceData: function() {
 
                        var i, campaign, j, banner, keepCampaign,
-                               filteredChoiceData = [];
+                               filteredChoiceData = [],
+                               now = new Date(),
+                               campaignStartDateWLeeway,
+                               campaignEndDateWLeeway;
 
                        for ( i = 0; i < this.choiceData.length; i++ ) {
+
                                campaign = this.choiceData[i];
                                keepCampaign = false;
 
+                               // Check choice data freshness
+                               campaignStartDateWLeeway = new Date();
+                               campaignStartDateWLeeway.setTime(
+                                       ( campaign.start * 1000 ) -
+                                       ( this.CAMPAIGN_STALENESS_LEEWAY * 
60000 )
+                               );
+
+                               campaignEndDateWLeeway = new Date();
+                               campaignEndDateWLeeway.setTime(
+                                       ( campaign.end * 1000  ) +;
+                                       ( this.CAMPAIGN_STALENESS_LEEWAY * 
60000 )
+                               )
+
+                               if ( ( campaignStartDateWLeeway > now ) ||
+                                       ( campaignEndDateWLeeway < now ) ) {
+
+                                       // Quick bow-out if the data is stale
+                                       this.choiceData = [];
+                                       return;
+                               }
+
                                // Filter for country if geotargeted
                                if ( campaign.geotargeted &&
                                        ( $.inArray(

-- 
To view, visit https://gerrit.wikimedia.org/r/201349
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib0f2ede85083d9568190f0211bd80f68e745f171
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to