From 9a9c22ea07c5bb8cff11082118e9fb30be9efb93 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Mon, 2 May 2011 20:29:44 +0000 Subject: [PATCH] * (bug 20468) User::invalidateCache throws 1205: Lock wait timeout exceeded Severly limit the number of calls that actually update the database (for no gain!). Leaving stuff that needs to update memcached Still, there's probably quite a lot of these calls which are still superfluous --- includes/User.php | 12 +++++++----- includes/specials/SpecialUserlogin.php | 2 +- includes/specials/SpecialUserrights.php | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/User.php b/includes/User.php index 9d62ef68e3..308b6e3b39 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1734,7 +1734,7 @@ class User { $wgMemc->set( $key, $val ? 1 : 0, 1800 ); } if ( $changed ) { - $this->invalidateCache(); + $this->invalidateCache( true ); } } @@ -1767,13 +1767,15 @@ class User { * Immediately touch the user data cache for this account. * Updates user_touched field, and removes account data from memcached * for reload on the next hit. + * + * @param $doDatabaseUpdate bool Do you really need to update the database? Really? */ - function invalidateCache() { + function invalidateCache( $doDatabaseUpdate = false ) { if( wfReadOnly() ) { return; } $this->load(); - if( $this->mId ) { + if( $this->mId && $doDatabaseUpdate ) { $this->mTouched = self::newTouchedTimestamp(); $dbw = wfGetDB( DB_MASTER ); @@ -2236,7 +2238,7 @@ class User { $this->mGroups[] = $group; $this->mRights = User::getGroupPermissions( $this->getEffectiveGroups( true ) ); - $this->invalidateCache(); + $this->invalidateCache( true ); } /** @@ -2258,7 +2260,7 @@ class User { $this->mGroups = array_diff( $this->mGroups, array( $group ) ); $this->mRights = User::getGroupPermissions( $this->getEffectiveGroups( true ) ); - $this->invalidateCache(); + $this->invalidateCache( true ); } /** diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index 25fc6f9a81..559591278e 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -658,7 +658,7 @@ class LoginForm extends SpecialPage { $wgUser->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 ); $wgUser->saveSettings(); } else { - $wgUser->invalidateCache(); + $wgUser->invalidateCache( true ); } $wgUser->setCookies(); self::clearLoginToken(); diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php index 140b59762c..6d59a8340d 100644 --- a/includes/specials/SpecialUserrights.php +++ b/includes/specials/SpecialUserrights.php @@ -231,7 +231,7 @@ class UserrightsPage extends SpecialPage { $newGroups = array_unique( $newGroups ); // Ensure that caches are cleared - $user->invalidateCache(); + $user->invalidateCache( true ); wfDebug( 'oldGroups: ' . print_r( $oldGroups, true ) ); wfDebug( 'newGroups: ' . print_r( $newGroups, true ) ); -- 2.20.1