From f661f3373eb500949b7e421b0df5a955d2904809 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Fri, 1 Feb 2019 01:54:08 +0000 Subject: [PATCH] Cache redirects from Special:Redirect People sometimes link these from high traffic places, so it is important to cache in varnish. File's with height can change so only cache that for 10 seconds. Also change from 302 to 301. Change-Id: I87a60c812cd1aa78a36359090c0cb8390be7183f --- includes/specials/SpecialRedirect.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/includes/specials/SpecialRedirect.php b/includes/specials/SpecialRedirect.php index 1b2bda9a93..c4e4635ab5 100644 --- a/includes/specials/SpecialRedirect.php +++ b/includes/specials/SpecialRedirect.php @@ -119,7 +119,9 @@ class SpecialRedirect extends FormSpecialPage { // ... and we can if ( $mto && !$mto->isError() ) { // ... change the URL to point to a thumbnail. - $url = $mto->getUrl(); + // Note: This url is more temporary as can change + // if file is reuploaded and has different aspect ratio. + $url = [ $mto->getUrl(), $height === -1 ? 301 : 302 ]; } } @@ -224,7 +226,21 @@ class SpecialRedirect extends FormSpecialPage { break; } if ( $status && $status->isGood() ) { - $this->getOutput()->redirect( $status->getValue() ); + // These urls can sometimes be linked from prominent places, + // so varnish cache. + $value = $status->getValue(); + if ( is_array( $value ) ) { + list( $url, $code ) = $value; + } else { + $url = $value; + $code = 301; + } + if ( $code === 301 ) { + $this->getOutput()->setCdnMaxage( 60 * 60 ); + } else { + $this->getOutput()->setCdnMaxage( 10 ); + } + $this->getOutput()->redirect( $url, $code ); return true; } -- 2.20.1