r49925 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49924‎ | r49925 | r49926 >
Date:03:51, 27 April 2009
Author:werdna
Status:resolved (Comments)
Tags:
Comment:
Fix problem where cached user objects would not update when default user options were changed. Now, only the option *overrides* are stored in the cache, and the options themselves are built from the defaults + overrides per request.
Modified paths:
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -119,8 +119,7 @@
120120 // user_group table
121121 'mGroups',
122122 // user_properties table
123 - 'mOptions',
124 - 'mOptionsLoaded',
 123+ 'mOptionOverrides',
125124 );
126125
127126 /**
@@ -189,8 +188,8 @@
190189 /** @name Cache variables */
191190 //@{
192191 var $mId, $mName, $mRealName, $mPassword, $mNewpassword, $mNewpassTime,
193 - $mEmail, $mOptions, $mTouched, $mToken, $mEmailAuthenticated,
194 - $mEmailToken, $mEmailTokenExpires, $mRegistration, $mGroups;
 192+ $mEmail, $mTouched, $mToken, $mEmailAuthenticated,
 193+ $mEmailToken, $mEmailTokenExpires, $mRegistration, $mGroups, $mOptionOverrides;
195194 //@}
196195
197196 /**
@@ -213,7 +212,7 @@
214213 //@{
215214 var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mSkin, $mRights,
216215 $mBlockreason, $mBlock, $mEffectiveGroups, $mBlockedGlobally,
217 - $mLocked, $mHideName;
 216+ $mLocked, $mHideName, $mOptions;
218217 //@}
219218
220219 /**
@@ -283,7 +282,7 @@
284283 # Try cache
285284 $key = wfMemcKey( 'user', 'id', $this->mId );
286285 $data = $wgMemc->get( $key );
287 - if ( !is_array( $data ) || $data['mVersion'] < MW_USER_VERSION ) {
 286+ if ( !is_array( $data ) || $data['mVersion'] < 'MW_USER_VERSION' ) {
288287 # Object is expired, load from DB
289288 $data = false;
290289 }
@@ -773,7 +772,8 @@
774773 $this->mPassword = $this->mNewpassword = '';
775774 $this->mNewpassTime = null;
776775 $this->mEmail = '';
777 - $this->mOptions = null; # Defer init
 776+ $this->mOptionOverrides = null;
 777+ $this->mOptionsLoaded = false;
778778
779779 if ( isset( $_COOKIE[$wgCookiePrefix.'LoggedOut'] ) ) {
780780 $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgCookiePrefix.'LoggedOut'] );
@@ -972,6 +972,7 @@
973973 $this->mSkin = null;
974974 $this->mRights = null;
975975 $this->mEffectiveGroups = null;
 976+ $this->mOptions = array();
976977
977978 if ( $reloadFrom ) {
978979 $this->mDataLoaded = false;
@@ -2297,10 +2298,11 @@
22982299 * @private
22992300 */
23002301 function decodeOptions( $str ) {
2301 - if ($str)
2302 - $this->mOptionsLoaded = true;
2303 - else
 2302+ if (!$str)
23042303 return;
 2304+
 2305+ $this->mOptionsLoaded = true;
 2306+ $this->mOptionOverrides = array();
23052307
23062308 $this->mOptions = array();
23072309 $a = explode( "\n", $str );
@@ -2308,6 +2310,7 @@
23092311 $m = array();
23102312 if ( preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
23112313 $this->mOptions[$m[1]] = $m[2];
 2314+ $this->mOptionOverrides[$m[1]] = $m[2];
23122315 }
23132316 }
23142317 }
@@ -3513,18 +3516,29 @@
35143517 return;
35153518
35163519 $this->mOptions = self::getDefaultOptions();
3517 -
3518 - // Load from database
3519 - $dbr = wfGetDB( DB_SLAVE );
35203520
3521 - $res = $dbr->select( 'user_properties',
3522 - '*',
3523 - array('up_user' => $this->getId()),
3524 - __METHOD__
3525 - );
 3521+ // Maybe load from the object
35263522
3527 - while( $row = $dbr->fetchObject( $res ) ) {
3528 - $this->mOptions[$row->up_property] = $row->up_value;
 3523+ if ( !is_null($this->mOptionOverrides) ) {
 3524+ wfDebug( "Loading options for user ".$this->getId()." from override cache.\n" );
 3525+ foreach( $this->mOptionOverrides as $key => $value ) {
 3526+ $this->mOptions[$key] = $value;
 3527+ }
 3528+ } else {
 3529+ wfDebug( "Loading options for user ".$this->getId()." from database.\n" );
 3530+ // Load from database
 3531+ $dbr = wfGetDB( DB_SLAVE );
 3532+
 3533+ $res = $dbr->select( 'user_properties',
 3534+ '*',
 3535+ array('up_user' => $this->getId()),
 3536+ __METHOD__
 3537+ );
 3538+
 3539+ while( $row = $dbr->fetchObject( $res ) ) {
 3540+ $this->mOptionOverrides[$row->up_property] = $row->up_value;
 3541+ $this->mOptions[$row->up_property] = $row->up_value;
 3542+ }
35293543 }
35303544
35313545 $this->mOptionsLoaded = true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r49945Clean up remnants from half-done solutions in r49925, per comments on code re...werdna12:04, 27 April 2009
r110910Fixed a bug in User::loadOptions(), probably introduced in r49925, causing th...tstarling05:25, 8 February 2012

Comments

#Comment by Robb1989 (talk | contribs)   12:00, 27 April 2009

Shouldn't it be $this->mOptions = null; instead of $this->mOptions = array(); in line 975 (clearInstanceCache())? Otherwise the default options don't seem to be loaded in getOption(). And I wonder why the version is no longer compared to the constant but to a fixed string in line 285, looks wrong.

#Comment by Werdna (talk | contribs)   12:05, 27 April 2009

Thanks for the reports, fixed in r49945.

Status & tagging log