Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/247310
Change subject: objectcache: Introduce BagOStuff:TTL_ constants for common values ...................................................................... objectcache: Introduce BagOStuff:TTL_ constants for common values Change-Id: I20fde9fa5cddcc9e92fa6a02b05dc7effa846742 --- M includes/Block.php M includes/Collation.php M includes/SiteStats.php M includes/User.php M includes/filerepo/ForeignAPIRepo.php M includes/jobqueue/JobQueueGroup.php M includes/libs/objectcache/BagOStuff.php M includes/libs/objectcache/WANObjectCache.php M includes/media/TransformationalImageHandler.php M includes/page/WikiPage.php M includes/parser/DateFormatter.php M includes/parser/Preprocessor_DOM.php M includes/parser/Preprocessor_Hash.php M includes/specials/SpecialUserlogin.php M includes/upload/UploadBase.php M thumb.php 16 files changed, 37 insertions(+), 29 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/10/247310/1 diff --git a/includes/Block.php b/includes/Block.php index 0ec4ad1..aba0a24 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -687,7 +687,7 @@ $lines = $wgMemc->get( $key ); if ( !$lines ) { $lines = explode( "\n", wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() ); - $wgMemc->set( $key, $lines, 3600 * 24 ); + $wgMemc->set( $key, $lines, BagOStuff::TTL_DAY ); } wfDebug( "Checking the autoblock whitelist..\n" ); diff --git a/includes/Collation.php b/includes/Collation.php index 40e8627..9e4e5ff 100644 --- a/includes/Collation.php +++ b/includes/Collation.php @@ -508,7 +508,7 @@ // Save to cache $this->firstLetterData = $data; - $cache->set( $cacheKey, $data, 86400 * 7 /* 1 week */ ); + $cache->set( $cacheKey, $data, BagOStuff::TTL_WEEK ); return $data; } diff --git a/includes/SiteStats.php b/includes/SiteStats.php index 76e7f7e..dec9a53 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -192,7 +192,7 @@ array( 'ug_group' => $group ), __METHOD__ ); - $wgMemc->set( $key, $hit, 3600 ); + $wgMemc->set( $key, $hit, BagOStuff::TTL_HOUR ); } self::$groupMemberCounts[$group] = $hit; } diff --git a/includes/User.php b/includes/User.php index 0dfdfc4..7be5740 100644 --- a/includes/User.php +++ b/includes/User.php @@ -454,7 +454,7 @@ $key = wfMemcKey( 'user', 'id', $this->mId ); $opts = Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); - ObjectCache::getMainWANInstance()->set( $key, $data, 3600, $opts ); + ObjectCache::getMainWANInstance()->set( $key, $data, BagOStuff::TTL_HOUR, $opts ); } /** @name newFrom*() static factory methods */ diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 4ffbf4a..23dcc0d 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -55,11 +55,11 @@ ); protected $fileFactory = array( 'ForeignAPIFile', 'newFromTitle' ); - /** @var int Check back with Commons after a day (24*60*60) */ - protected $apiThumbCacheExpiry = 86400; + /** @var int Check back with Commons after this expiry */ + protected $apiThumbCacheExpiry = 86400; // 1 day (24*3600) - /** @var int Redownload thumbnail files after a month (86400*30) */ - protected $fileCacheExpiry = 2592000; + /** @var int Redownload thumbnail files after this expiry */ + protected $fileCacheExpiry = 2592000; // 1 month (30*24*3600) /** @var array */ protected $mFileExists = array(); diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index 5bd1cc9..ebd6222 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -394,7 +394,7 @@ return $value['v']; } else { $value = $wgConf->getConfig( $this->wiki, $name ); - $wgMemc->set( $key, array( 'v' => $value ), 86400 + mt_rand( 0, 86400 ) ); + $wgMemc->set( $key, array( 'v' => $value ), BagOStuff::TTL_DAY + mt_rand( 0, BagOStuff::TTL_DAY ) ); return $value; } diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index fc74985..871c30c 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -64,6 +64,14 @@ const ERR_UNREACHABLE = 2; // can't connect const ERR_UNEXPECTED = 3; // response gave some error + // Constants for TTL values, in seconds + const TTL_MINUTE = 60; + const TTL_HOUR = 3600; + const TTL_DAY = 24 * 3600; // 86400 + const TTL_WEEK = 7 * 24 * 3600; // 604800 + const TTL_MONTH = 30 * 24 * 3600; // 2592000 + const TTL_YEAR = 365 * 24 * 3600; // 31536000 + /** Bitfield constants for get()/getMulti() */ const READ_LATEST = 1; // use latest data for replicated stores const READ_VERIFIED = 2; // promise that caller can tell when keys are stale @@ -313,7 +321,7 @@ } } - $expiry = min( $expiry ?: INF, 86400 ); + $expiry = min( $expiry ?: INF, BagOStuff::TTL_DAY ); $this->clearLastError(); $timestamp = microtime( true ); // starting UNIX timestamp @@ -382,7 +390,7 @@ * @since 1.26 */ final public function getScopedLock( $key, $timeout = 6, $expiry = 30, $rclass = '' ) { - $expiry = min( $expiry ?: INF, 86400 ); + $expiry = min( $expiry ?: INF, BagOStuff::TTL_DAY ); if ( !$this->lock( $key, $timeout, $expiry, $rclass ) ) { return null; @@ -575,7 +583,7 @@ * @return int */ protected function convertExpiry( $exptime ) { - if ( ( $exptime != 0 ) && ( $exptime < 86400 * 3650 /* 10 years */ ) ) { + if ( $exptime != 0 && $exptime < ( 10 * TTL_YEAR ) ) { return time() + $exptime; } else { return $exptime; @@ -590,7 +598,7 @@ * @return int */ protected function convertToRelative( $exptime ) { - if ( $exptime >= 86400 * 3650 /* 10 years */ ) { + if ( $exptime >= ( 10 * self::TTL_YEAR ) ) { $exptime -= time(); if ( $exptime <= 0 ) { $exptime = 1; diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 1a0e9bb..edfdb94 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -83,7 +83,7 @@ const HOLDOFF_TTL = 14; // MAX_COMMIT_DELAY + MAX_REPLICA_LAG + MAX_SNAPSHOT_LAG + 1 /** Seconds to keep dependency purge keys around */ - const CHECK_KEY_TTL = 31536000; // 1 year + const CHECK_KEY_TTL = BagOStuff::TTL_YEAR; /** Seconds to keep lock keys around */ const LOCK_TTL = 5; /** Default remaining TTL at which to consider pre-emptive regeneration */ @@ -284,7 +284,7 @@ * // Fetch the row from the DB * $row = $dbr->selectRow( ... ); * $key = wfMemcKey( 'building', $buildingId ); - * $cache->set( $key, $row, 86400, $setOpts ); + * $cache->set( $key, $row, BagOStuff::TTL_DAY, $setOpts ); * @endcode * * @param string $key Cache key @@ -538,8 +538,8 @@ * $catInfo = $cache->getWithSetCallback( * // Key to store the cached value under * wfMemcKey( 'cat-attributes', $catId ), - * // Time-to-live (seconds) - * 60, + * // Time-to-live (in seconds) + * BagOStuff::TTL_MINUTE, * // Function that derives the new key value * function ( $oldValue, &$ttl, array &$setOpts ) { * $dbr = wfGetDB( DB_SLAVE ); @@ -556,8 +556,8 @@ * $catConfig = $cache->getWithSetCallback( * // Key to store the cached value under * wfMemcKey( 'site-cat-config' ), - * // Time-to-live (seconds) - * 86400, + * // Time-to-live (in seconds) + * BagOStuff::TTL_DAY, * // Function that derives the new key value * function ( $oldValue, &$ttl, array &$setOpts ) { * $dbr = wfGetDB( DB_SLAVE ); @@ -608,7 +608,7 @@ * $lastCatActions = $cache->getWithSetCallback( * // Key to store the cached value under * wfMemcKey( 'cat-last-actions', 100 ), - * // Time-to-live (seconds) + * // Time-to-live (in seconds) * 10, * // Function that derives the new key value * function ( $oldValue, &$ttl, array &$setOpts ) { diff --git a/includes/media/TransformationalImageHandler.php b/includes/media/TransformationalImageHandler.php index 15753a9..304c6c7 100644 --- a/includes/media/TransformationalImageHandler.php +++ b/includes/media/TransformationalImageHandler.php @@ -523,7 +523,7 @@ return null; } - $wgMemc->set( "imagemagick-version", $matches[1], 3600 ); + $wgMemc->set( "imagemagick-version", $matches[1], BagOStuff::TTL_HOUR ); return $matches[1]; } diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 3ec3e89..0e23178 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -2907,7 +2907,7 @@ // Show log excerpt on 404 pages rather than just a link $key = wfMemcKey( 'page-recent-delete', md5( $logTitle->getPrefixedText() ) ); - ObjectCache::getMainStashInstance()->set( $key, 1, 86400 ); + ObjectCache::getMainStashInstance()->set( $key, 1, BagOStuff::TTL_DAY ); $this->doDeleteUpdates( $id, $content ); diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index ef295ab..f19bd38 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -133,7 +133,7 @@ $dateFormatter = $wgMemc->get( $key ); if ( !$dateFormatter ) { $dateFormatter = new DateFormatter( $lang ); - $wgMemc->set( $key, $dateFormatter, 3600 ); + $wgMemc->set( $key, $dateFormatter, BagOStuff::TTL_HOUR ); } } return $dateFormatter; diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index c329689..bb8a50b 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -167,7 +167,7 @@ if ( $xml === false ) { $xml = $this->preprocessToXml( $text, $flags ); $cacheValue = sprintf( "%08d", self::CACHE_VERSION ) . $xml; - $wgMemc->set( $cacheKey, $cacheValue, 86400 ); + $wgMemc->set( $cacheKey, $cacheValue, BagOStuff::TTL_DAY ); wfDebugLog( "Preprocessor", "Saved preprocessor XML to memcached (key $cacheKey)" ); } } else { diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 49fa8a1..e3eb974 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -737,7 +737,7 @@ // T111289: Cache values should not exceed 1 Mb, but they do. if ( strlen( $cacheValue ) <= 1e6 ) { - $wgMemc->set( $cacheKey, $cacheValue, 86400 ); + $wgMemc->set( $cacheKey, $cacheValue, BagOStuff::TTL_DAY ); wfDebugLog( "Preprocessor", "Saved preprocessor Hash to memcached (key $cacheKey)" ); } } diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index 0da598b..e682fa6 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -635,7 +635,7 @@ $key = wfMemcKey( 'acctcreate', 'ip', $ip ); $value = $wgMemc->get( $key ); if ( !$value ) { - $wgMemc->set( $key, 0, 86400 ); + $wgMemc->set( $key, 0, BagOStuff::TTL_DAY ); } if ( $value >= $wgAccountCreationThrottle ) { return Status::newFatal( 'acct_creation_throttle_hit', $wgAccountCreationThrottle ); diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index f600e32..e214f20 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1968,7 +1968,7 @@ if ( $value === false ) { $cache->delete( $key ); } else { - $cache->set( $key, $value, 86400 ); + $cache->set( $key, $value, BagOStuff::TTL_DAY ); } } } diff --git a/thumb.php b/thumb.php index bd14e41..786e6fc 100644 --- a/thumb.php +++ b/thumb.php @@ -392,7 +392,7 @@ if ( !$done ) { // transform() gave a fatal global $wgMemc; // Randomize TTL to reduce stampedes - $wgMemc->incrWithInit( $key, 3600 + mt_rand( 0, 300 ) ); + $wgMemc->incrWithInit( $key, BagOStuff::TTL_HOUR + mt_rand( 0, 300 ) ); } } ); @@ -445,7 +445,7 @@ if ( !$thumb || $thumb->isError() ) { // Randomize TTL to reduce stampedes - $wgMemc->incrWithInit( $key, 3600 + mt_rand( 0, 300 ) ); + $wgMemc->incrWithInit( $key, BagOStuff::TTL_HOUR + mt_rand( 0, 300 ) ); } return array( $thumb, $errorHtml ); -- To view, visit https://gerrit.wikimedia.org/r/247310 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I20fde9fa5cddcc9e92fa6a02b05dc7effa846742 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits