r40118 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40117‎ | r40118 | r40119 >
Date:01:09, 28 August 2008
Author:demon
Status:old
Tags:
Comment:
Add some caching to the group counts.
Modified paths:
  • /trunk/phase3/includes/SiteStats.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SiteStats.php
@@ -114,9 +114,16 @@
115115 */
116116 static function numberingroup($group) {
117117 if ( !isset( self::$groupMemberCounts[$group] ) ) {
118 - $dbr = wfGetDB( DB_SLAVE );
119 - self::$groupMemberCounts[$group] = $dbr->selectField( 'user_groups', 'COUNT(*)',
 118+ global $wgMemc;
 119+ $key = wfMemcKey( 'SiteStats', 'groupcounts', $group );
 120+ $hit = $wgMemc->get( $key );
 121+ if ( !$hit ) {
 122+ $dbr = wfGetDB( DB_SLAVE );
 123+ $hit = $dbr->selectField( 'user_groups', 'COUNT(*)',
120124 array( 'ug_group' => $group ), __METHOD__ );
 125+ $wgMemc->set( $key, $hit, 3600 );
 126+ }
 127+ self::$groupMemberCounts[$group] = $hit;
121128 }
122129 return self::$groupMemberCounts[$group];
123130 }

Status & tagging log