jenkins-bot has submitted this change and it was merged.

Change subject: Split CentralAuthUser::queryAttached into cheap and expensive 
part
......................................................................


Split CentralAuthUser::queryAttached into cheap and expensive part

CentralAuthUser::queryAttached does a single query to look up attached
status and then four queries per attached wiki to extend it with
local data. Local data is not always needed, so split out the cheap part.

This should also reduce the impact of T119736.

Change-Id: I1da755ad9eacd417c8d2c348fb3ff577b5fcf60d
(cherry picked from commit ea6847504659607ceec46e39eaa3f74c95bd11e1)
---
M includes/CentralAuthUser.php
M tests/phpunit/CentralAuthUserTest.php
2 files changed, 43 insertions(+), 13 deletions(-)

Approvals:
  Thcipriani: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php
index 8d3f11e..083400c 100644
--- a/includes/CentralAuthUser.php
+++ b/includes/CentralAuthUser.php
@@ -695,7 +695,7 @@
                        return $this->mHomeWiki;
                }
 
-               $attached = $this->queryAttached();
+               $attached = $this->queryAttachedBasic();
 
                if ( !count( $attached ) ) {
                        return null;
@@ -708,9 +708,9 @@
                        }
                }
 
-               // Still null... try harder.
                if ( $this->mHomeWiki === null || $this->mHomeWiki === '' ) {
-                       reset( $attached );
+                       // Still null... try harder.
+                       $attached = $this->queryAttached();
                        $this->mHomeWiki = key( $attached ); // Make sure we 
always have some value
                        $maxEdits = -1;
                        foreach ( $attached as $wiki => $acc ) {
@@ -2223,9 +2223,39 @@
         *    wiki                  The wiki ID (database name)
         *    attachedTimestamp     The MW timestamp when the account was 
attached
         *    attachedMethod        Attach method: password, mail or primary
+        *    ...                   All information returned by localUserData()
         */
        public function queryAttached() {
                // Cache $wikis to avoid expensive query whenever possible
+               // mAttachedInfo is shared with queryAttachedBasic(); check 
whether it contains partial data
+               if (
+                       $this->mAttachedInfo !== null
+                       && ( !$this->mAttachedInfo || array_key_exists( 'id', 
reset( $this->mAttachedInfo ) ) )
+               ) {
+                       return $this->mAttachedInfo;
+               }
+
+               $wikis = $this->queryAttachedBasic();
+
+               foreach ( $wikis as $wikiId => $_ ) {
+                       $localUser = $this->localUserData( $wikiId );
+                       $wikis[$wikiId] = array_merge( $wikis[$wikiId], 
$localUser );
+               }
+
+               $this->mAttachedInfo = $wikis;
+
+               return $wikis;
+       }
+
+       /**
+        * Helper method for queryAttached().
+        *
+        * Does the cheap part of the lookup by checking the cross-wiki 
localuser table,
+        * and returns attach time and method.
+        *
+        * @return array
+        */
+       protected function queryAttachedBasic() {
                if ( $this->mAttachedInfo !== null ) {
                        return $this->mAttachedInfo;
                }
@@ -2248,16 +2278,9 @@
                        $wikis[$row->lu_wiki] = array(
                                'wiki' => $row->lu_wiki,
                                'attachedTimestamp' => wfTimestampOrNull( TS_MW,
-                                        $row->lu_attached_timestamp ),
+                                       $row->lu_attached_timestamp ),
                                'attachedMethod' => $row->lu_attached_method,
                        );
-
-                       $localUser = $this->localUserData( $row->lu_wiki );
-
-                       // Just for fun, add local user data.
-                       // Displayed in the steward interface.
-                       $wikis[$row->lu_wiki] = array_merge( 
$wikis[$row->lu_wiki],
-                               $localUser );
                }
 
                $this->mAttachedInfo = $wikis;
@@ -2286,6 +2309,8 @@
 
        /**
         * Fetch a row of user data needed for migration.
+        *
+        * Returns most data in the user and ipblocks tables, user groups, and 
editcount.
         *
         * @param $wikiID String
         * @throws Exception if local user not found
@@ -2835,4 +2860,4 @@
        private function clearLocalUserCache( $wikiId, $userId ) {
                User::purge( $wikiId, $userId );
        }
-}
+}
\ No newline at end of file
diff --git a/tests/phpunit/CentralAuthUserTest.php 
b/tests/phpunit/CentralAuthUserTest.php
index 766e7a9..4535343 100644
--- a/tests/phpunit/CentralAuthUserTest.php
+++ b/tests/phpunit/CentralAuthUserTest.php
@@ -46,9 +46,14 @@
                /** @var 
PHPUnit_Framework_MockObject_MockObject|CentralAuthUser $ca */
                $ca = $this->getMockBuilder( 'CentralAuthUser' )
                        ->disableOriginalConstructor()
-                       ->setMethods( array( 'queryAttached', 'loadState' ) )
+                       ->setMethods( array( 'queryAttachedBasic', 
'queryAttached', 'loadState' ) )
                        ->getMock();
 
+               $ca->expects( $this->any() )->method( 'queryAttachedBasic' 
)->will( $this->returnValue(
+                       array_map( function ( $data ) {
+                               return array_intersect_key( $data, array( 
'attachedMethod' => true ) );
+                       }, $attached )
+               ) );
                $ca->expects( $this->any() )->method( 'queryAttached' )->will( 
$this->returnValue( $attached ) );
                $this->assertEquals( $expected, $ca->getHomeWiki() );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/295231
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1da755ad9eacd417c8d2c348fb3ff577b5fcf60d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: wmf/1.28.0-wmf.6
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Thcipriani <tcipri...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to