jenkins-bot has submitted this change and it was merged. Change subject: Convert the top X reviewers cache to the main stash ......................................................................
Convert the top X reviewers cache to the main stash This avoids DB_MASTER queries on page views. Bug: T92357 Change-Id: I16306318a8813ad879a19c381dd1c10d8fa65b6f --- M backend/FlaggedRevsStats.php M frontend/specialpages/reports/ValidationStatistics_body.php 2 files changed, 29 insertions(+), 27 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/backend/FlaggedRevsStats.php b/backend/FlaggedRevsStats.php index 9b364fa..76f39e5 100644 --- a/backend/FlaggedRevsStats.php +++ b/backend/FlaggedRevsStats.php @@ -8,7 +8,7 @@ * If no $timestamp is specified, then the latest will be used. * * @param $timestamp string|bool false TS_ timestamp - * @return Array of current FR stats + * @return array of current FR stats */ public static function getStats( $timestamp = false ) { $data = array(); // initialize @@ -81,9 +81,9 @@ } // Set key to limit duplicate updates... - $dbCache = wfGetCache( CACHE_DB ); - $keySQL = wfMemcKey( 'flaggedrevs', 'statsUpdating' ); - $dbCache->set( $keySQL, '1', $wgFlaggedRevsStatsAge ); + $stash = ObjectCache::getMainStashInstance(); + $keySQL = $stash->makeKey( 'flaggedrevs', 'statsUpdating' ); + $stash->set( $keySQL, '1', $wgFlaggedRevsStatsAge ); // Get total, reviewed, and synced page count for each namespace list( $ns_total, $ns_reviewed, $ns_synced ) = self::getPerNamespaceTotals(); @@ -93,9 +93,9 @@ $avePET = self::getMeanPendingEditTime(); # Get wait (till review) time samples for anon edits... - $reviewDataAnon = self::getEditReviewTimes( $dbCache, 'anons' ); + $reviewDataAnon = self::getEditReviewTimes( $stash, 'anons' ); # Get wait (till review) time samples for logged-in user edits... - $reviewDataUser = self::getEditReviewTimes( $dbCache, 'users' ); + $reviewDataUser = self::getEditReviewTimes( $stash, 'users' ); $dbw = wfGetDB( DB_MASTER ); // The timestamp to identify this whole batch of data @@ -184,9 +184,9 @@ $dbw->insert( 'flaggedrevs_statistics', $dataSet, __FUNCTION__, array( 'IGNORE' ) ); // Stats are now up to date! - $key = wfMemcKey( 'flaggedrevs', 'statsUpdated' ); - $dbCache->set( $key, '1', $wgFlaggedRevsStatsAge ); - $dbCache->delete( $keySQL ); + $key = $stash->makeKey( 'flaggedrevs', 'statsUpdated' ); + $stash->set( $key, '1', $wgFlaggedRevsStatsAge ); + $stash->delete( $keySQL ); } private static function getPerNamespaceTotals() { @@ -234,12 +234,12 @@ /** * Get edit review time statistics (as recent as possible) - * @param $dbCache cache object + * @param $stash BagOStuff object * @param $users string "anons" or "users" * @throws Exception - * @return Array associative + * @return array associative */ - private static function getEditReviewTimes( $dbCache, $users = 'anons' ) { + private static function getEditReviewTimes( $stash, $users = 'anons' ) { $result = array( 'average' => 0, 'median' => 0, @@ -345,7 +345,7 @@ $timeCondition = "rev_timestamp BETWEEN $encMinTS AND $encMaxTS"; # Get mod for edit spread $ecKey = wfMemcKey( 'flaggedrevs', 'rcEditCount', $users, $days ); - $edits = (int)$dbCache->get( $ecKey ); + $edits = (int)$stash->get( $ecKey ); if ( !$edits ) { $edits = (int)$dbr->selectField( array('page','revision'), 'COUNT(*)', @@ -356,7 +356,7 @@ 'page_namespace' => FlaggedRevs::getReviewNamespaces() ) ); - $dbCache->set( $ecKey, $edits, 14*24*3600 ); // cache for 2 weeks + $stash->set( $ecKey, $edits, 14*24*3600 ); // cache for 2 weeks } $mod = max( floor( $edits/$sampleSize ), 1 ); # $mod >= 1 # For edits that started off pending, how long do they take to get reviewed? @@ -409,12 +409,12 @@ $aveRT = ($secondsR + $secondsP)/$sampleSize; // sample mean sort($times); // order smallest -> largest // Sample median - $rank = round( count($times)/2 + .5 ) - 1; + $rank = intval( round( count($times)/2 + .5 ) - 1 ); $medianRT = $times[$rank]; // Make percentile tabulation data $doPercentiles = array( 35, 45, 55, 65, 75, 85, 90, 95 ); foreach ( $doPercentiles as $percentile ) { - $rank = round( $percentile*count($times)/100 + .5 ) - 1; + $rank = intval( round( $percentile*count($times)/100 + .5 ) - 1 ); $rPerTable[$percentile] = $times[$rank]; } $result['average'] = $aveRT; diff --git a/frontend/specialpages/reports/ValidationStatistics_body.php b/frontend/specialpages/reports/ValidationStatistics_body.php index 57018a3..d42522e 100644 --- a/frontend/specialpages/reports/ValidationStatistics_body.php +++ b/frontend/specialpages/reports/ValidationStatistics_body.php @@ -199,14 +199,14 @@ return false; } - $dbCache = wfGetCache( CACHE_DB ); - $key = wfMemcKey( 'flaggedrevs', 'statsUpdated' ); - $keySQL = wfMemcKey( 'flaggedrevs', 'statsUpdating' ); + $stash = ObjectCache::getMainStashInstance(); + $key = $stash->makeKey( 'flaggedrevs', 'statsUpdated' ); + $keySQL = $stash->makeKey( 'flaggedrevs', 'statsUpdating' ); // If a cache update is needed, do so asynchronously. // Don't trigger query while another is running. - if ( $dbCache->get( $key ) ) { + if ( $stash->get( $key ) ) { wfDebugLog( 'ValidationStatistics', __METHOD__ . " skipping, got data" ); - } elseif ( $dbCache->get( $keySQL ) ) { + } elseif ( $stash->get( $keySQL ) ) { wfDebugLog( 'ValidationStatistics', __METHOD__ . " skipping, in progress" ); } else { global $wgPhpCli; @@ -299,16 +299,16 @@ protected function getTopReviewers() { global $wgFlaggedRevsStats; - $key = wfMemcKey( 'flaggedrevs', 'reviewTopUsers' ); - $dbCache = wfGetCache( CACHE_DB ); - $data = $dbCache->get( $key ); + $stash = ObjectCache::getMainStashInstance(); + $key = $stash->makeKey( 'flaggedrevs', 'reviewTopUsers' ); + $data = $stash->get( $key ); if ( is_array( $data ) ) { return $data; // cache hit } + + $dbr = wfGetDB( DB_SLAVE, 'vslow' ); $limit = (int)$wgFlaggedRevsStats['topReviewersCount']; $seconds = 3600*$wgFlaggedRevsStats['topReviewersHours']; - - $dbr = wfGetDB( DB_SLAVE ); $cutoff = $dbr->timestamp( time() - $seconds ); $res = $dbr->select( 'logging', array( 'log_user', 'COUNT(*) AS reviews' ), @@ -321,12 +321,14 @@ __METHOD__, array( 'GROUP BY' => 'log_user', 'ORDER BY' => 'reviews DESC', 'LIMIT' => $limit ) ); + $data = array(); foreach ( $res as $row ) { $data[$row->log_user] = $row->reviews; } + // Save/cache users - $dbCache->set( $key, $data, 3600 ); + $stash->set( $key, $data, 3600 ); return $data; } -- To view, visit https://gerrit.wikimedia.org/r/287891 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I16306318a8813ad879a19c381dd1c10d8fa65b6f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/FlaggedRevs Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits