jenkins-bot has submitted this change and it was merged. Change subject: SpecialBannerLoader: reduce s-maxage on caught exception ......................................................................
SpecialBannerLoader: reduce s-maxage on caught exception Bug: T151418 Change-Id: Ife88332be3da95edfb3741b8af7fd9c2ab7c926f --- M README M extension.json M special/SpecialBannerLoader.php 3 files changed, 31 insertions(+), 7 deletions(-) Approvals: Ejegg: Looks good to me, but someone else must approve Awight: Looks good to me, approved jenkins-bot: Verified diff --git a/README b/README index 8acd140..29eabe6 100644 --- a/README +++ b/README @@ -111,9 +111,15 @@ used, and that subpage will contain a short explanation. Default: false -* $wgNoticeBannerMaxAge: Server-side banner cache timeout in seconds +* $wgNoticeBannerMaxAge: Server-side banner cache timeout, in seconds, for + anonymous users. Default: 600 +* $wgNoticeBannerReducedMaxAge: Reduced server-side banner cache timeout, in + seconds, for anonymous users, when SpecialBannerLoader catches an exception. + We lower the expiry in the hope that the error will go away the next time this + resource is requested. + * $wgNoticeUseTranslateExtension: Whether to use the Translation extension for banner message translation Default: false diff --git a/extension.json b/extension.json index 553a463..140a9db 100644 --- a/extension.json +++ b/extension.json @@ -436,6 +436,7 @@ "NoticeHideUrls": [], "CentralNoticeHideBannersP3P": false, "NoticeBannerMaxAge": 600, + "NoticeBannerReducedMaxAge": 120, "NoticeUseTranslateExtension": false, "NoticeUseLanguageConversion": false, "NoticeProtectGroup": "sysop", diff --git a/special/SpecialBannerLoader.php b/special/SpecialBannerLoader.php index 7265ef0..d015448 100644 --- a/special/SpecialBannerLoader.php +++ b/special/SpecialBannerLoader.php @@ -9,6 +9,9 @@ */ const CAMPAIGN_STALENESS_LEEWAY = 900; + const MAX_CACHE_NORMAL = 0; + const MAX_CACHE_REDUCED = 1; + /** @var string Name of the chosen banner */ public $bannerName; /** @var string Name of the campaign that the banner belongs to.*/ @@ -22,24 +25,28 @@ } function execute( $par ) { - $this->sendHeaders(); + $this->getOutput()->disable(); try { $this->getParams(); $out = $this->getJsNotice( $this->bannerName ); + $cacheResponse = self::MAX_CACHE_NORMAL; } catch ( EmptyBannerException $e ) { $out = "mw.centralNotice.handleBannerLoaderError( 'Empty banner' );"; + $cacheResponse = self::MAX_CACHE_REDUCED; } catch ( Exception $e ) { $msg = $e->getMessage(); $msgParamStr = $msg ? " '{$msg}' " : ''; $out = "mw.centralNotice.handleBannerLoaderError({$msgParamStr});"; + $cacheResponse = self::MAX_CACHE_REDUCED; wfDebugLog( 'CentralNotice', $msg ); } + $this->sendHeaders( $cacheResponse ); echo $out; } @@ -73,17 +80,27 @@ /** * Generate the HTTP response headers for the banner file + * @param cacheResponse int If the response will be cached, use the normal + * cache time ($wgNoticeBannerMaxAge) or the reduced time + * ($wgNoticeBannerReducedMaxAge). */ - function sendHeaders() { - global $wgJsMimeType, $wgNoticeBannerMaxAge; + function sendHeaders( $cacheResponse = self::MAX_CACHE_NORMAL ) { + global $wgJsMimeType, $wgNoticeBannerMaxAge, $wgNoticeBannerReducedMaxAge; header( "Content-type: $wgJsMimeType; charset=utf-8" ); if ( !$this->getUser()->isLoggedIn() ) { - // Public users get cached - header( "Cache-Control: public, s-maxage={$wgNoticeBannerMaxAge}, max-age=0" ); + + // This header tells our front-end caches to retain the content for + // $sMaxAge seconds. + $sMaxAge = ( $cacheResponse === self::MAX_CACHE_NORMAL ) ? + $wgNoticeBannerMaxAge : $wgNoticeBannerReducedMaxAge; + + header( "Cache-Control: public, s-maxage={$sMaxAge}, max-age=0" ); } else { - // Private users do not (we have to emit this because we've disabled output) + // Private users do not get cached (we have to emit this because + // we've disabled output) + // TODO Couldn't we cache for theses users? See T149873 header( "Cache-Control: private, s-maxage=0, max-age=0" ); } } -- To view, visit https://gerrit.wikimedia.org/r/322976 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ife88332be3da95edfb3741b8af7fd9c2ab7c926f Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/CentralNotice Gerrit-Branch: master Gerrit-Owner: AndyRussG <andrew.green...@gmail.com> Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com> Gerrit-Reviewer: Awight <awi...@wikimedia.org> Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Ssmith <ssm...@wikimedia.org> Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits