Martineznovo has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/385418 )
Change subject: Change "sepoch" Last-Modified calculations constant in periods
of time
......................................................................
Change "sepoch" Last-Modified calculations constant in periods of time
The current implementation calculates a date that moves every second. The date
is always $wgSquidMaxage seconds before "now".
The default value of $wgSquidMaxage is 18000 seconds (5 hours). If a page is
last modified more than 5 hours ago, the $modifiedTimes['sepoch'] timestamp
will likely be the most recent one, and the Last-Modified: header will be
constantly moving every second, making each request with an If-Last-Modified
header return the full page again instead of the cached one.
To prevent a cache stampede, it's reasonable to distribute page expirations
across a range of time instead of use a fixed time for each page. But the
calculation shouldn't be a function that returns a time that moves each
second. Ideally it should move every $wgSquidMaxage seconds.
This patch calculates the period between last update of the page and the
current date, divided by the SquidMaxage to get the number of periods
between them. Then adds those periods to the last modification date to get
the last period before the current date.
Bug: T178629
Change-Id: Idac0bef5e5a6284301a2dc47799237ae2da1f1f5
---
M includes/OutputPage.php
1 file changed, 5 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/18/385418/1
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 7a2b7df..6c1b8b9 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -788,15 +788,17 @@
return false;
}
- $timestamp = wfTimestamp( TS_MW, $timestamp );
$modifiedTimes = [
- 'page' => $timestamp,
+ 'page' => wfTimestamp( TS_MW, $timestamp ),
'user' => $this->getUser()->getTouched(),
'epoch' => $config->get( 'CacheEpoch' )
];
if ( $config->get( 'UseSquid' ) ) {
// T46570: the core page itself may not change, but
resources might
- $modifiedTimes['sepoch'] = wfTimestamp( TS_MW, time() -
$config->get( 'SquidMaxage' ) );
+ // Force an updated date every SquidMaxage period since
last page update
+ $period = $config->get( 'SquidMaxage' );
+ $ages = floor( ( time() - $timestamp ) / $period );
+ $modifiedTimes['sepoch'] = wfTimestamp( TS_MW,
$timestamp + $period * $ages );
}
Hooks::run( 'OutputPageCheckLastModified', [ &$modifiedTimes,
$this ] );
--
To view, visit https://gerrit.wikimedia.org/r/385418
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idac0bef5e5a6284301a2dc47799237ae2da1f1f5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Martineznovo <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits