Use a secondary db connection for Revsion::getParentLength in api
authorumherirrender <umherirrender_de.wp@web.de>
Sun, 2 Mar 2014 18:07:06 +0000 (19:07 +0100)
committerSpringle <springle@wikimedia.org>
Tue, 4 Mar 2014 02:10:22 +0000 (02:10 +0000)
Getting api connection before the connection is set to the named
connection and store it in a local var to use it later.
Same comment as in Special:Contributions

Bug: 61982
Change-Id: Ia66c4a65a24876e2a528034e8e003aa535e6b689

includes/api/ApiQueryUserContributions.php

index 9ad77d4..16108a2 100644 (file)
@@ -56,6 +56,11 @@ class ApiQueryContributions extends ApiQueryBase {
                $this->fld_patrolled = isset( $prop['patrolled'] );
                $this->fld_tags = isset( $prop['tags'] );
 
+               // Most of this code will use the 'contributions' group DB, which can map to slaves
+               // with extra user based indexes or partioning by user. The additional metadata
+               // queries should use a regular slave since the lookup pattern is not all by user.
+               $dbSecondary = $this->getDB(); // any random slave
+
                // TODO: if the query is going only against the revision table, should this be done?
                $this->selectNamedDB( 'contributions', DB_SLAVE, 'contributions' );
 
@@ -90,7 +95,7 @@ class ApiQueryContributions extends ApiQueryBase {
                                        $revIds[] = $row->rev_parent_id;
                                }
                        }
-                       $this->parentLens = Revision::getParentLengths( $this->getDB(), $revIds );
+                       $this->parentLens = Revision::getParentLengths( $dbSecondary, $revIds );
                        $res->rewind(); // reset
                }