* store user_editcount inside cached user object

* load editcount together with user.*, avoid multiple queries
-- this removes additional query (or queries)
This commit is contained in:
Domas Mituzas 2007-02-15 14:27:15 +00:00
parent 64b6715453
commit 86efcb1a31

View file

@ -8,7 +8,7 @@
define( 'USER_TOKEN_LENGTH', 32 ); define( 'USER_TOKEN_LENGTH', 32 );
# Serialized record version # Serialized record version
define( 'MW_USER_VERSION', 4 ); define( 'MW_USER_VERSION', 5 );
# Some punctuation to prevent editing from broken text-mangling proxies. # Some punctuation to prevent editing from broken text-mangling proxies.
# FIXME: this is embedded unescaped into HTML attributes in various # FIXME: this is embedded unescaped into HTML attributes in various
@ -93,7 +93,7 @@ class User {
'mEmailToken', 'mEmailToken',
'mEmailTokenExpires', 'mEmailTokenExpires',
'mRegistration', 'mRegistration',
'mEditCount',
# user_group table # user_group table
'mGroups', 'mGroups',
); );
@ -187,7 +187,6 @@ class User {
# Try cache # Try cache
$key = wfMemcKey( 'user', 'id', $this->mId ); $key = wfMemcKey( 'user', 'id', $this->mId );
$data = $wgMemc->get( $key ); $data = $wgMemc->get( $key );
if ( !is_array( $data ) || $data['mVersion'] < MW_USER_VERSION ) { if ( !is_array( $data ) || $data['mVersion'] < MW_USER_VERSION ) {
# Object is expired, load from DB # Object is expired, load from DB
$data = false; $data = false;
@ -540,6 +539,8 @@ class User {
/** /**
* Count the number of edits of a user * Count the number of edits of a user
* *
* It should not be static and some day should be merged as proper member function / deprecated -- domas
*
* @param int $uid The user ID to check * @param int $uid The user ID to check
* @return int * @return int
* @static * @static
@ -547,7 +548,6 @@ class User {
static function edits( $uid ) { static function edits( $uid ) {
wfProfileIn( __METHOD__ ); wfProfileIn( __METHOD__ );
$dbr = wfGetDB( DB_SLAVE ); $dbr = wfGetDB( DB_SLAVE );
// check if the user_editcount field has been initialized // check if the user_editcount field has been initialized
$field = $dbr->selectField( $field = $dbr->selectField(
'user', 'user_editcount', 'user', 'user_editcount',
@ -738,6 +738,8 @@ class User {
$this->mEmailToken = $s->user_email_token; $this->mEmailToken = $s->user_email_token;
$this->mEmailTokenExpires = wfTimestampOrNull( TS_MW, $s->user_email_token_expires ); $this->mEmailTokenExpires = wfTimestampOrNull( TS_MW, $s->user_email_token_expires );
$this->mRegistration = wfTimestampOrNull( TS_MW, $s->user_registration ); $this->mRegistration = wfTimestampOrNull( TS_MW, $s->user_registration );
$this->mEditCount = $s->user_editcount;
$this->getEditCount(); // revalidation for nulls
# Load group data # Load group data
$res = $dbr->select( 'user_groups', $res = $dbr->select( 'user_groups',
@ -1570,11 +1572,9 @@ class User {
global $wgAutoConfirmAge, $wgAutoConfirmCount; global $wgAutoConfirmAge, $wgAutoConfirmCount;
$accountAge = time() - wfTimestampOrNull( TS_UNIX, $this->mRegistration ); $accountAge = time() - wfTimestampOrNull( TS_UNIX, $this->mRegistration );
$accountEditCount = User::edits( $this->mId ); if( $accountAge >= $wgAutoConfirmAge && $this->getEditCount() >= $wgAutoConfirmCount ) {
if( $accountAge >= $wgAutoConfirmAge && $accountEditCount >= $wgAutoConfirmCount ) {
$this->mEffectiveGroups[] = 'autoconfirmed'; $this->mEffectiveGroups[] = 'autoconfirmed';
} }
# Implicit group for users whose email addresses are confirmed # Implicit group for users whose email addresses are confirmed
global $wgEmailAuthentication; global $wgEmailAuthentication;
if( self::isValidEmailAddr( $this->mEmail ) ) { if( self::isValidEmailAddr( $this->mEmail ) ) {
@ -1589,7 +1589,21 @@ class User {
} }
return $this->mEffectiveGroups; return $this->mEffectiveGroups;
} }
/* Return the edit count for the user. This is where User::edits should have been */
function getEditCount() {
if ($this->mId) {
if ($this->mEditCount === null ) {
/* Populate the count, if it has not been populated yet */
$this->mEditCount = User::edits($this->mId);
}
return $this->mEditCount;
} else {
/* nil */
return null;
}
}
/** /**
* Add the user to the given group. * Add the user to the given group.
* This takes immediate effect. * This takes immediate effect.
@ -2544,6 +2558,8 @@ class User {
__METHOD__ ); __METHOD__ );
} }
} }
// edit count in user cache too
$this->invalidateCache();
} }
} }