jenkins-bot has submitted this change and it was merged.
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. A 15-minute leeway is also
built in to allow for cache refresh time.
Bug: T88276
Change-Id: Ib0f2ede85083d9568190f0211bd80f68e745f171
---
M modules/ext.centralNotice.bannerController/bannerController.lib.js
1 file changed, 26 insertions(+), 3 deletions(-)
Approvals:
Awight: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ext.centralNotice.bannerController/bannerController.lib.js
b/modules/ext.centralNotice.bannerController/bannerController.lib.js
index 84d9e08..ae331fb 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,40 @@
/**
* 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 have already ended,
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(),
+ campaignEndDateWLeeway;
for ( i = 0; i < this.choiceData.length; i++ ) {
+
campaign = this.choiceData[i];
keepCampaign = false;
+ // Check choice data freshness
+ campaignEndDateWLeeway = new Date();
+ campaignEndDateWLeeway.setTime(
+ ( campaign.end * 1000 ) +
+ ( this.CAMPAIGN_STALENESS_LEEWAY *
60000 )
+ );
+
+ // Quick bow-out if the data is stale
+ if ( campaignEndDateWLeeway < now ) {
+ 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: merged
Gerrit-Change-Id: Ib0f2ede85083d9568190f0211bd80f68e745f171
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits