[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Job to update links for a given title. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 * http://www.gnu.org/copyleft/gpl.html 19 * 20 * @file 21 * @ingroup JobQueue 22 */ 23 24 /** 25 * Background job to update links for titles in certain backlink range by page ID. 26 * Newer version for high use templates. This is deprecated by RefreshLinksPartitionJob. 27 * 28 * @ingroup JobQueue 29 * @deprecated since 1.23 30 */ 31 class RefreshLinksJob2 extends Job { 32 function __construct( $title, $params ) { 33 parent::__construct( 'refreshLinks2', $title, $params ); 34 // Base jobs for large templates can easily be de-duplicated 35 $this->removeDuplicates = !isset( $params['start'] ) && !isset( $params['end'] ); 36 } 37 38 /** 39 * Run a refreshLinks2 job 40 * @return bool Success 41 */ 42 function run() { 43 global $wgUpdateRowsPerJob; 44 45 $linkCache = LinkCache::singleton(); 46 $linkCache->clear(); 47 48 if ( is_null( $this->title ) ) { 49 $this->error = "refreshLinks2: Invalid title"; 50 return false; 51 } 52 53 // Back compat for pre-r94435 jobs 54 $table = isset( $this->params['table'] ) ? $this->params['table'] : 'templatelinks'; 55 56 // Avoid slave lag when fetching templates. 57 // When the outermost job is run, we know that the caller that enqueued it must have 58 // committed the relevant changes to the DB by now. At that point, record the master 59 // position and pass it along as the job recursively breaks into smaller range jobs. 60 // Hopefully, when leaf jobs are popped, the slaves will have reached that position. 61 if ( isset( $this->params['masterPos'] ) ) { 62 $masterPos = $this->params['masterPos']; 63 } elseif ( wfGetLB()->getServerCount() > 1 ) { 64 $masterPos = wfGetLB()->getMasterPos(); 65 } else { 66 $masterPos = false; 67 } 68 69 $tbc = $this->title->getBacklinkCache(); 70 71 $jobs = array(); // jobs to insert 72 if ( isset( $this->params['start'] ) && isset( $this->params['end'] ) ) { 73 # This is a partition job to trigger the insertion of leaf jobs... 74 $jobs = array_merge( $jobs, $this->getSingleTitleJobs( $table, $masterPos ) ); 75 } else { 76 # This is a base job to trigger the insertion of partitioned jobs... 77 if ( $tbc->getNumLinks( $table, $wgUpdateRowsPerJob + 1 ) <= $wgUpdateRowsPerJob ) { 78 # Just directly insert the single per-title jobs 79 $jobs = array_merge( $jobs, $this->getSingleTitleJobs( $table, $masterPos ) ); 80 } else { 81 # Insert the partition jobs to make per-title jobs 82 foreach ( $tbc->partition( $table, $wgUpdateRowsPerJob ) as $batch ) { 83 list( $start, $end ) = $batch; 84 $jobs[] = new RefreshLinksJob2( $this->title, 85 array( 86 'table' => $table, 87 'start' => $start, 88 'end' => $end, 89 'masterPos' => $masterPos, 90 ) + $this->getRootJobParams() // carry over information for de-duplication 91 ); 92 } 93 } 94 } 95 96 if ( count( $jobs ) ) { 97 JobQueueGroup::singleton()->push( $jobs ); 98 } 99 100 return true; 101 } 102 103 /** 104 * @param string $table 105 * @param mixed $masterPos 106 * @return array 107 */ 108 protected function getSingleTitleJobs( $table, $masterPos ) { 109 # The "start"/"end" fields are not set for the base jobs 110 $start = isset( $this->params['start'] ) ? $this->params['start'] : false; 111 $end = isset( $this->params['end'] ) ? $this->params['end'] : false; 112 $titles = $this->title->getBacklinkCache()->getLinks( $table, $start, $end ); 113 # Convert into single page refresh links jobs. 114 # This handles well when in sapi mode and is useful in any case for job 115 # de-duplication. If many pages use template A, and that template itself 116 # uses template B, then an edit to both will create many duplicate jobs. 117 # Roughly speaking, for each page, one of the "RefreshLinksJob" jobs will 118 # get run first, and when it does, it will remove the duplicates. Of course, 119 # one page could have its job popped when the other page's job is still 120 # buried within the logic of a refreshLinks2 job. 121 $jobs = array(); 122 foreach ( $titles as $title ) { 123 $jobs[] = new RefreshLinksJob( $title, 124 array( 'masterPos' => $masterPos ) + $this->getRootJobParams() 125 ); // carry over information for de-duplication 126 } 127 return $jobs; 128 } 129 130 /** 131 * @return array 132 */ 133 public function getDeduplicationInfo() { 134 $info = parent::getDeduplicationInfo(); 135 // Don't let highly unique "masterPos" values ruin duplicate detection 136 if ( is_array( $info['params'] ) ) { 137 unset( $info['params']['masterPos'] ); 138 } 139 return $info; 140 } 141 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |