Remove redundant $db->resultObject() calls
authorKevin Israel <pleasestand@live.com>
Fri, 12 Sep 2014 04:12:38 +0000 (00:12 -0400)
committerUmherirrender <umherirrender_de.wp@web.de>
Fri, 19 Sep 2014 20:35:55 +0000 (20:35 +0000)
DatabaseBase::query() already passes the value returned by the
database driver (usually an object or resource for SELECT queries)
through $db->resultObject(). There is no need to pass it through
the method a second time to get a ResultWrapper.

Change-Id: I5d34ab2bffb7f236d2f824b4ef0e8670f89d4599

includes/Export.php
includes/search/SearchMssql.php
includes/search/SearchOracle.php
includes/search/SearchPostgres.php
includes/specialpage/QueryPage.php
includes/specials/SpecialUndelete.php

index 48a814d..84f5c60 100644 (file)
@@ -267,7 +267,7 @@ class WikiExporter {
                        if ( $this->buffer == WikiExporter::STREAM ) {
                                $prev = $this->db->bufferResults( false );
                        }
-                       $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
+                       $result = null; // Assuring $result is not undefined, if exception occurs early
                        try {
                                $result = $this->db->select( array( 'logging', 'user' ),
                                        array( "{$logging}.*", 'user_name' ), // grab the user name
@@ -275,8 +275,7 @@ class WikiExporter {
                                        __METHOD__,
                                        array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
                                );
-                               $wrapper = $this->db->resultObject( $result );
-                               $this->outputLogStream( $wrapper );
+                               $this->outputLogStream( $result );
                                if ( $this->buffer == WikiExporter::STREAM ) {
                                        $this->db->bufferResults( $prev );
                                }
@@ -286,8 +285,8 @@ class WikiExporter {
 
                                // Freeing result
                                try {
-                                       if ( $wrapper ) {
-                                               $wrapper->free();
+                                       if ( $result ) {
+                                               $result->free();
                                        }
                                } catch ( Exception $e2 ) {
                                        // Already in panic mode -> ignoring $e2 as $e has
@@ -377,16 +376,15 @@ class WikiExporter {
                                $prev = $this->db->bufferResults( false );
                        }
 
-                       $wrapper = null; // Assuring $wrapper is not undefined, if exception occurs early
+                       $result = null; // Assuring $result is not undefined, if exception occurs early
                        try {
                                wfRunHooks( 'ModifyExportQuery',
                                                array( $this->db, &$tables, &$cond, &$opts, &$join ) );
 
                                # Do the query!
                                $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
-                               $wrapper = $this->db->resultObject( $result );
                                # Output dump results
-                               $this->outputPageStream( $wrapper );
+                               $this->outputPageStream( $result );
 
                                if ( $this->buffer == WikiExporter::STREAM ) {
                                        $this->db->bufferResults( $prev );
@@ -397,8 +395,8 @@ class WikiExporter {
 
                                // Freeing result
                                try {
-                                       if ( $wrapper ) {
-                                               $wrapper->free();
+                                       if ( $result ) {
+                                               $result->free();
                                        }
                                } catch ( Exception $e2 ) {
                                        // Already in panic mode -> ignoring $e2 as $e has
@@ -467,7 +465,7 @@ class WikiExporter {
        }
 
        /**
-        * @param array $resultset
+        * @param ResultWrapper $resultset
         */
        protected function outputLogStream( $resultset ) {
                foreach ( $resultset as $row ) {
index de701f7..0d7970d 100644 (file)
@@ -34,10 +34,7 @@ class SearchMssql extends SearchDatabase {
         * @access public
         */
        function searchText( $term ) {
-               $resultSet = $this->db->resultObject(
-                       $this->db->query( $this->getQuery( $this->filter( $term ), true ) )
-               );
-
+               $resultSet = $this->db->query( $this->getQuery( $this->filter( $term ), true ) );
                return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
 
@@ -49,10 +46,7 @@ class SearchMssql extends SearchDatabase {
         * @access public
         */
        function searchTitle( $term ) {
-               $resultSet = $this->db->resultObject(
-                       $this->db->query( $this->getQuery( $this->filter( $term ), false ) )
-               );
-
+               $resultSet = $this->db->query( $this->getQuery( $this->filter( $term ), false ) );
                return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
 
index 348da79..5821148 100644 (file)
@@ -69,10 +69,7 @@ class SearchOracle extends SearchDatabase {
                        return new SqlSearchResultSet( false, '' );
                }
 
-               $resultSet = $this->db->resultObject(
-                       $this->db->query( $this->getQuery( $this->filter( $term ), true ) )
-               );
-
+               $resultSet = $this->db->query( $this->getQuery( $this->filter( $term ), true ) );
                return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
 
@@ -87,10 +84,7 @@ class SearchOracle extends SearchDatabase {
                        return new SqlSearchResultSet( false, '' );
                }
 
-               $resultSet = $this->db->resultObject(
-                       $this->db->query( $this->getQuery( $this->filter( $term ), false ) )
-               );
-
+               $resultSet = $this->db->query( $this->getQuery( $this->filter( $term ), false ) );
                return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
 
index c64c845..59b0c31 100644 (file)
@@ -40,7 +40,7 @@ class SearchPostgres extends SearchDatabase {
        function searchTitle( $term ) {
                $q = $this->searchQuery( $term, 'titlevector', 'page_title' );
                $olderror = error_reporting( E_ERROR );
-               $resultSet = $this->db->resultObject( $this->db->query( $q, 'SearchPostgres', true ) );
+               $resultSet = $this->db->query( $q, 'SearchPostgres', true );
                error_reporting( $olderror );
                return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
@@ -48,7 +48,7 @@ class SearchPostgres extends SearchDatabase {
        function searchText( $term ) {
                $q = $this->searchQuery( $term, 'textvector', 'old_text' );
                $olderror = error_reporting( E_ERROR );
-               $resultSet = $this->db->resultObject( $this->db->query( $q, 'SearchPostgres', true ) );
+               $resultSet = $this->db->query( $q, 'SearchPostgres', true );
                error_reporting( $olderror );
                return new SqlSearchResultSet( $resultSet, $this->searchTerms );
        }
index 8943996..b229e06 100644 (file)
@@ -406,7 +406,7 @@ abstract class QueryPage extends SpecialPage {
                        $res = $dbr->query( $sql, $fname );
                }
 
-               return $dbr->resultObject( $res );
+               return $res;
        }
 
        /**
index cfadddb..c3e871b 100644 (file)
@@ -99,7 +99,7 @@ class PageArchive {
         * @return bool|ResultWrapper
         */
        protected static function listPages( $dbr, $condition ) {
-               return $dbr->resultObject( $dbr->select(
+               return $dbr->select(
                        array( 'archive' ),
                        array(
                                'ar_namespace',
@@ -113,7 +113,7 @@ class PageArchive {
                                'ORDER BY' => array( 'ar_namespace', 'ar_title' ),
                                'LIMIT' => 100,
                        )
-               ) );
+               );
        }
 
        /**
@@ -152,15 +152,13 @@ class PageArchive {
                        $options
                );
 
-               $res = $dbr->select( $tables,
+               return $dbr->select( $tables,
                        $fields,
                        $conds,
                        __METHOD__,
                        $options,
                        $join_conds
                );
-
-               return $dbr->resultObject( $res );
        }
 
        /**
@@ -177,15 +175,13 @@ class PageArchive {
                }
 
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select(
+               return $dbr->select(
                        'filearchive',
                        ArchivedFile::selectFields(),
                        array( 'fa_name' => $this->title->getDBkey() ),
                        __METHOD__,
                        array( 'ORDER BY' => 'fa_timestamp DESC' )
                );
-
-               return $dbr->resultObject( $res );
        }
 
        /**
@@ -532,9 +528,8 @@ class PageArchive {
                        __METHOD__,
                        /* options */ array( 'ORDER BY' => 'ar_timestamp' )
                );
-               $ret = $dbw->resultObject( $result );
-               $rev_count = $dbw->numRows( $result );
 
+               $rev_count = $result->numRows();
                if ( !$rev_count ) {
                        wfDebug( __METHOD__ . ": no revisions to restore\n" );
 
@@ -544,10 +539,10 @@ class PageArchive {
                        return $status;
                }
 
-               $ret->seek( $rev_count - 1 ); // move to last
-               $row = $ret->fetchObject(); // get newest archived rev
+               $result->seek( $rev_count - 1 ); // move to last
+               $row = $result->fetchObject(); // get newest archived rev
                $oldPageId = (int)$row->ar_page_id; // pass this to ArticleUndelete hook
-               $ret->seek( 0 ); // move back
+               $result->seek( 0 ); // move back
 
                // grab the content to check consistency with global state before restoring the page.
                $revision = Revision::newFromArchiveRow( $row,
@@ -589,7 +584,7 @@ class PageArchive {
                $revision = null;
                $restored = 0;
 
-               foreach ( $ret as $row ) {
+               foreach ( $result as $row ) {
                        // Check for key dupes due to shitty archive integrity.
                        if ( $row->ar_rev_id ) {
                                $exists = $dbw->selectField( 'revision', '1',