More profiling points for Linker::link(). And that's enough work on it for the moment.
[lhc/web/wiklou.git] / includes / HTMLCacheUpdate.php
index 94aa6ce..1f25021 100644 (file)
@@ -5,21 +5,23 @@
  * Small numbers of links will be done immediately, large numbers are pushed onto
  * the job queue.
  *
- * This class is designed to work efficiently with small numbers of links, and 
+ * This class is designed to work efficiently with small numbers of links, and
  * to work reasonably well with up to ~10^5 links. Above ~10^6 links, the memory
  * and time requirements of loading all backlinked IDs in doUpdate() might become
  * prohibitive. The requirements measured at Wikimedia are approximately:
- * 
+ *
  *   memory: 48 bytes per row
  *   time: 16us per row for the query plus processing
  *
  * The reason this query is done is to support partitioning of the job
- * by backlinked ID. The memory issue could be allieviated by doing this query in 
+ * by backlinked ID. The memory issue could be allieviated by doing this query in
  * batches, but of course LIMIT with an offset is inefficient on the DB side.
  *
- * The class is nevertheless a vast improvement on the previous method of using 
+ * The class is nevertheless a vast improvement on the previous method of using
  * Image::getLinksTo() and Title::touchArray(), which uses about 2KB of memory per
  * link.
+ *
+ * @ingroup Cache
  */
 class HTMLCacheUpdate
 {
@@ -40,15 +42,14 @@ class HTMLCacheUpdate
                $cond = $this->getToCondition();
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( $this->mTable, $this->getFromField(), $cond, __METHOD__ );
-               $resWrap = new ResultWrapper( $dbr, $res );
+
                if ( $dbr->numRows( $res ) != 0 ) {
                        if ( $dbr->numRows( $res ) > $this->mRowsPerJob ) {
-                               $this->insertJobs( $resWrap );
+                               $this->insertJobs( $res );
                        } else {
-                               $this->invalidateIDs( $resWrap );
+                               $this->invalidateIDs( $res );
                        }
                }
-               $dbr->freeResult( $res );
        }
 
        function insertJobs( ResultWrapper $res ) {
@@ -67,7 +68,7 @@ class HTMLCacheUpdate
                                        break;
                                }
                        }
-                       
+
                        $params = array(
                                'table' => $this->mTable,
                                'start' => $start,
@@ -87,7 +88,8 @@ class HTMLCacheUpdate
                        'imagelinks' => 'il',
                        'categorylinks' => 'cl',
                        'templatelinks' => 'tl',
-                       
+                       'redirect' => 'rd',
+
                        # Not needed
                        # 'externallinks' => 'el',
                        # 'langlinks' => 'll'
@@ -101,22 +103,20 @@ class HTMLCacheUpdate
                }
                return $this->mPrefix;
        }
-       
+
        function getFromField() {
                return $this->getPrefix() . '_from';
        }
 
        function getToCondition() {
+               $prefix = $this->getPrefix();
                switch ( $this->mTable ) {
                        case 'pagelinks':
-                               return array( 
-                                       'pl_namespace' => $this->mTitle->getNamespace(),
-                                       'pl_title' => $this->mTitle->getDBkey()
-                               );
                        case 'templatelinks':
+                       case 'redirect':
                                return array(
-                                       'tl_namespace' => $this->mTitle->getNamespace(),
-                                       'tl_title' => $this->mTitle->getDBkey()
+                                       "{$prefix}_namespace" => $this->mTitle->getNamespace(),
+                                       "{$prefix}_title" => $this->mTitle->getDBkey()
                                );
                        case 'imagelinks':
                                return array( 'il_to' => $this->mTitle->getDBkey() );
@@ -139,7 +139,7 @@ class HTMLCacheUpdate
                $dbw = wfGetDB( DB_MASTER );
                $timestamp = $dbw->timestamp();
                $done = false;
-               
+
                while ( !$done ) {
                        # Get all IDs in this query into an array
                        $ids = array();
@@ -156,10 +156,10 @@ class HTMLCacheUpdate
                        if ( !count( $ids ) ) {
                                break;
                        }
-                       
+
                        # Update page_touched
-                       $dbw->update( 'page', 
-                               array( 'page_touched' => $timestamp ), 
+                       $dbw->update( 'page',
+                               array( 'page_touched' => $timestamp ),
                                array( 'page_id IN (' . $dbw->makeList( $ids ) . ')' ),
                                __METHOD__
                        );
@@ -186,6 +186,7 @@ class HTMLCacheUpdate
 
 /**
  * @todo document (e.g. one-sentence top-level class description).
+ * @ingroup JobQueue
  */
 class HTMLCacheUpdateJob extends Job {
        var $table, $start, $end;
@@ -217,10 +218,8 @@ class HTMLCacheUpdateJob extends Job {
 
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( $this->table, $fromField, $conds, __METHOD__ );
-               $update->invalidateIDs( new ResultWrapper( $dbr, $res ) );
-               $dbr->freeResult( $res );
+               $update->invalidateIDs( $res );
 
                return true;
        }
 }
-?>