OutputPage: Inline getCdnCacheEpoch() into checkLastModified()

This useless function contains useful documentation, that is best
kept with the rest of the business logic. It is only used once and
is literally `a - b`.

Change-Id: I650c37c4655bcc6edcd12186b24b0b1bd3faafd2
This commit is contained in:
Timo Tijhof 2024-07-18 23:59:52 +01:00 committed by James D. Forrester
parent e1a871bd1d
commit 0ea6d7ff32
2 changed files with 8 additions and 58 deletions

View file

@ -864,10 +864,14 @@ class OutputPage extends ContextSource {
'epoch' => $config->get( MainConfigNames::CacheEpoch )
];
if ( $config->get( MainConfigNames::UseCdn ) ) {
$modifiedTimes['sepoch'] = wfTimestamp( TS_MW, $this->getCdnCacheEpoch(
time(),
$config->get( MainConfigNames::CdnMaxAge )
) );
// Ensure Last-Modified is never more than "$wgCdnMaxAge" seconds in the past,
// because even if the wiki page hasn't been edited, other static resources may
// change (site configuration, default preferences, skin HTML, interface messages,
// URLs to other files and services) and must roll-over in a timely manner (T46570)
$modifiedTimes['sepoch'] = wfTimestamp(
TS_MW,
time() - $config->get( MainConfigNames::CdnMaxAge )
);
}
$this->getHookRunner()->onOutputPageCheckLastModified( $modifiedTimes, $this );
@ -930,19 +934,6 @@ class OutputPage extends ContextSource {
return true;
}
/**
* @param int $reqTime Time of request (eg. now)
* @param int $maxAge Cache TTL in seconds
* @return int Timestamp
*/
private function getCdnCacheEpoch( $reqTime, $maxAge ) {
// Ensure Last-Modified is never more than $wgCdnMaxAge in the past,
// because even if the wiki page content hasn't changed since, static
// resources may have changed (skin HTML, interface messages, urls, etc.)
// and must roll-over in a timely manner (T46570)
return $reqTime - $maxAge;
}
/**
* Override the last modified timestamp
*

View file

@ -679,47 +679,6 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
];
}
/**
* @dataProvider provideCdnCacheEpoch
*/
public function testCdnCacheEpoch( $params ) {
$out = TestingAccessWrapper::newFromObject( $this->newInstance() );
$reqTime = strtotime( $params['reqTime'] );
$pageTime = strtotime( $params['pageTime'] );
$actual = max( $pageTime, $out->getCdnCacheEpoch( $reqTime, $params['maxAge'] ) );
$this->assertEquals(
$params['expect'],
gmdate( DateTime::ATOM, $actual ),
'cdn epoch'
);
}
public static function provideCdnCacheEpoch() {
$base = [
'pageTime' => '2011-04-01T12:00:00+00:00',
'maxAge' => 24 * 3600,
];
return [
'after 1s' => [ $base + [
'reqTime' => '2011-04-01T12:00:01+00:00',
'expect' => '2011-04-01T12:00:00+00:00',
] ],
'after 23h' => [ $base + [
'reqTime' => '2011-04-02T11:00:00+00:00',
'expect' => '2011-04-01T12:00:00+00:00',
] ],
'after 24h and a bit' => [ $base + [
'reqTime' => '2011-04-02T12:34:56+00:00',
'expect' => '2011-04-01T12:34:56+00:00',
] ],
'after a year' => [ $base + [
'reqTime' => '2012-05-06T00:12:07+00:00',
'expect' => '2012-05-05T00:12:07+00:00',
] ],
];
}
// @todo How to test setLastModified?
public function testSetRobotPolicy() {