* (bug 20468) User::invalidateCache throws 1205: Lock wait timeout exceeded
authorSam Reed <reedy@users.mediawiki.org>
Mon, 2 May 2011 20:29:44 +0000 (20:29 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Mon, 2 May 2011 20:29:44 +0000 (20:29 +0000)
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
includes/specials/SpecialUserlogin.php
includes/specials/SpecialUserrights.php

index 9d62ef6..308b6e3 100644 (file)
@@ -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 );
        }
 
        /**
index 25fc6f9..5595912 100644 (file)
@@ -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();
index 140b597..6d59a83 100644 (file)
@@ -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 ) );