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

Change subject: Only select fields we need in WikiPageEntityRevisionLookup
......................................................................


Only select fields we need in WikiPageEntityRevisionLookup

Also avoid joining page if not needed.

Change-Id: I765b68e768ba1bc6ad1f59707b2df1e54bcaf10b
(cherry picked from commit 0859ecfc400c6fe1985221e4167d58c1041c944b)
---
M lib/includes/store/sql/WikiPageEntityRevisionLookup.php
1 file changed, 27 insertions(+), 25 deletions(-)

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



diff --git a/lib/includes/store/sql/WikiPageEntityRevisionLookup.php 
b/lib/includes/store/sql/WikiPageEntityRevisionLookup.php
index c84f503..0e311ca 100644
--- a/lib/includes/store/sql/WikiPageEntityRevisionLookup.php
+++ b/lib/includes/store/sql/WikiPageEntityRevisionLookup.php
@@ -117,7 +117,7 @@
         * @return int|false
         */
        public function getLatestRevisionId( EntityId $entityId ) {
-               $row = $this->loadPageRow( $entityId );
+               $row = $this->loadPageLatest( $entityId );
 
                if ( $row ) {
                        return (int)$row->page_latest;
@@ -148,6 +148,22 @@
        }
 
        /**
+        * Fields we need to select to load a revision
+        *
+        * @return string[]
+        */
+       private function selectFields() {
+               return array(
+                       'rev_id',
+                       'rev_content_format',
+                       'rev_timestamp',
+                       'old_id',
+                       'old_text',
+                       'old_flags'
+               );
+       }
+
+       /**
         * Selects revision information from the page, revision, and text 
tables.
         *
         * @since 0.4
@@ -159,39 +175,25 @@
         * @throws DBQueryError If the query fails.
         * @return object|null a raw database row object, or null if no such 
entity revision exists.
         */
-       protected function selectRevisionRow( EntityId $entityId, $revisionId = 
0, $connType = DB_SLAVE ) {
+       private function selectRevisionRow( EntityId $entityId, $revisionId = 
0, $connType = DB_SLAVE ) {
                wfProfileIn( __METHOD__ );
                $db = $this->getConnection( $connType );
-
-               $tables = array(
-                       'page',
-                       'revision',
-                       'text'
-               );
-
-               $pageTable = $db->tableName( 'page' );
-               $revisionTable = $db->tableName( 'revision' );
-               $textTable = $db->tableName( 'text' );
-
-               $vars = "$pageTable.*, $revisionTable.*, $textTable.*";
 
                $where = array();
                $join = array();
 
                if ( $revisionId > 0 ) {
+                       $tables = array( 'revision', 'text' );
+
                        // pick revision by id
                        $where['rev_id'] = $revisionId;
-
-                       // pick page via rev_page
-                       $join['page'] = array( 'INNER JOIN', 'page_id=rev_page' 
);
 
                        // pick text via rev_text_id
                        $join['text'] = array( 'INNER JOIN', 
'old_id=rev_text_id' );
 
                        wfDebugLog( __CLASS__, __FUNCTION__ . ": Looking up 
revision $revisionId of " . $entityId );
                } else {
-                       // entity to page mapping
-                       $tables[] = 'wb_entity_per_page';
+                       $tables = array( 'page', 'revision', 'text', 
'wb_entity_per_page' );
 
                        $entityId = $this->getProperEntityId( $entityId );
 
@@ -211,7 +213,7 @@
                        wfDebugLog( __CLASS__, __FUNCTION__ . ': Looking up 
latest revision of ' . $entityId );
                }
 
-               $res = $db->select( $tables, $vars, $where, __METHOD__, 
array(), $join );
+               $res = $db->select( $tables, $this->selectFields(), $where, 
__METHOD__, array(), $join );
 
                if ( !$res ) {
                        // this can only happen if the DB is set to ignore 
errors, which shouldn't be the case...
@@ -237,15 +239,15 @@
         * @throws DBQueryError
         * @return object|null
         */
-       private function loadPageRow( EntityId $entityId ) {
-               $row = $this->selectPageRow( $entityId );
+       private function loadPageLatest( EntityId $entityId ) {
+               $row = $this->selectPageLatest( $entityId );
 
                if ( !$row ) {
                        // try to load from master
                        wfDebugLog(  __CLASS__, __FUNCTION__ . ': try to load ' 
. $entityId
                                . ' from DB_MASTER.' );
 
-                       $row = $this->selectPageRow( $entityId, DB_MASTER );
+                       $row = $this->selectPageLatest( $entityId, DB_MASTER );
                }
 
                return $row;
@@ -262,7 +264,7 @@
         * @throws DBQueryError If the query fails.
         * @return object|null a raw database row object, or null if no such 
entity revision exists.
         */
-       protected function selectPageRow( EntityId $entityId, $connType = 
DB_SLAVE ) {
+       protected function selectPageLatest( EntityId $entityId, $connType = 
DB_SLAVE ) {
                wfProfileIn( __METHOD__ );
                $db = $this->getConnection( $connType );
 
@@ -283,7 +285,7 @@
                // pick page via epp_page_id
                $join['page'] = array( 'INNER JOIN', 'epp_page_id=page_id' );
 
-               $res = $db->select( $tables, '*', $where, __METHOD__, array(), 
$join );
+               $res = $db->select( $tables, 'page_latest', $where, __METHOD__, 
array(), $join );
 
                if ( !$res ) {
                        // this can only happen if the DB is set to ignore 
errors, which shouldn't be the case...

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I765b68e768ba1bc6ad1f59707b2df1e54bcaf10b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.25wmf12c
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to