* API query optimizations
[lhc/web/wiklou.git] / includes / api / ApiPageSet.php
index 7f3cdc9..ad3d804 100644 (file)
@@ -229,6 +229,16 @@ class ApiPageSet extends ApiQueryBase {
                $this->profileOut();
        }
 
+       /**
+        * Initialize PageSet from a list of Revision IDs
+        */
+       public function populateFromRevisionIDs($revIDs) {
+               $this->profileIn();
+               $pageIDs = array_map('intval', $revIDs); // paranoia
+               $this->initFromRevIDs($revIDs);
+               $this->profileOut();
+       }
+
        /**
         * Extract all requested fields from the row received from the database
         */
@@ -274,6 +284,9 @@ class ApiPageSet extends ApiQueryBase {
 
                // Get validated and normalized title objects
                $linkBatch = $this->processTitlesStrArray($titles);
+               if($linkBatch->isEmpty())
+                       return;
+                       
                $set = $linkBatch->constructSet('page', $db);
 
                // Get pageIDs data from the `page` table
@@ -289,8 +302,10 @@ class ApiPageSet extends ApiQueryBase {
        }
 
        private function initFromPageIds($pageids) {
+               if(empty($pageids))
+                       return;
+                       
                $db = $this->getDB();
-
                $set = array (
                        'page_id' => $pageids
                );
@@ -363,13 +378,16 @@ class ApiPageSet extends ApiQueryBase {
 
        private function initFromRevIDs($revids) {
 
+               if(empty($revids))
+                       return;
+                       
                $db = $this->getDB();
                $pageids = array();
                $remaining = array_flip($revids);
                
-               $tables = array('page', 'revision');
+               $tables = array('revision');
                $fields = array('rev_id','rev_page');
-               $where = array( 'rev_deleted' => 0, 'rev_id' => $revids );
+               $where = array('rev_deleted' => 0, 'rev_id' => $revids);
                
                // Get pageIDs data from the `page` table
                $this->profileDBIn();
@@ -389,9 +407,7 @@ class ApiPageSet extends ApiQueryBase {
                // Populate all the page information
                if($this->mResolveRedirects)
                        $this->dieDebug('revids may not be used with redirect resolution');
-               $pageids = array_keys($pageids);
-               if(!empty($pageids))
-                       $this->initFromPageIds($pageids);
+               $this->initFromPageIds(array_keys($pageids));
        }
 
        private function resolvePendingRedirects() {