Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
LinksUpdate | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
doJob | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
queueIncomingLinksJobs | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
isPrioritized | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Job; |
4 | |
5 | use CirrusSearch\Updater; |
6 | use MediaWiki\MediaWikiServices; |
7 | use Title; |
8 | |
9 | /** |
10 | * Performs the appropriate updates to Elasticsearch after a LinksUpdate is |
11 | * completed. The page itself is updated first then a second copy of this job |
12 | * is queued to update linked articles if any links change. The job can be |
13 | * 'prioritized' via the 'prioritize' parameter which will switch it to a |
14 | * different queue then the non-prioritized jobs. Prioritized jobs will never |
15 | * be deduplicated with non-prioritized jobs which is good because we can't |
16 | * control which job is removed during deduplication. In our case it'd only be |
17 | * ok to remove the non-prioritized version. |
18 | * |
19 | * This program is free software; you can redistribute it and/or modify |
20 | * it under the terms of the GNU General Public License as published by |
21 | * the Free Software Foundation; either version 2 of the License, or |
22 | * (at your option) any later version. |
23 | * |
24 | * This program is distributed in the hope that it will be useful, |
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27 | * GNU General Public License for more details. |
28 | * |
29 | * You should have received a copy of the GNU General Public License along |
30 | * with this program; if not, write to the Free Software Foundation, Inc., |
31 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
32 | * http://www.gnu.org/copyleft/gpl.html |
33 | */ |
34 | class LinksUpdate extends CirrusTitleJob { |
35 | public function __construct( Title $title, array $params ) { |
36 | parent::__construct( $title, $params ); |
37 | |
38 | if ( $this->isPrioritized() ) { |
39 | $this->command .= 'Prioritized'; |
40 | } |
41 | // Note that we have to keep the prioritized param or else when the job |
42 | // is loaded it'll load under a different name/command/type which would |
43 | // be confusing. |
44 | } |
45 | |
46 | /** |
47 | * @return bool |
48 | */ |
49 | protected function doJob() { |
50 | $updater = Updater::build( $this->getSearchConfig(), $this->params['cluster'] ?? null ); |
51 | $res = $updater->updateFromTitle( $this->title ); |
52 | if ( $res === false ) { |
53 | // Couldn't update. Bail early and retry rather than adding an |
54 | // IncomingLinkCount job that will produce the wrong answer. |
55 | return $res; |
56 | } |
57 | |
58 | if ( $this->getSearchConfig()->get( 'CirrusSearchEnableIncomingLinkCounting' ) ) { |
59 | $this->queueIncomingLinksJobs(); |
60 | } |
61 | |
62 | return $res; |
63 | } |
64 | |
65 | /** |
66 | * Queue IncomingLinkCount jobs when pages are newly linked or unlinked |
67 | */ |
68 | private function queueIncomingLinksJobs() { |
69 | $titleKeys = array_merge( $this->params[ 'addedLinks' ], |
70 | $this->params[ 'removedLinks' ] ); |
71 | $refreshInterval = $this->getSearchConfig()->get( 'CirrusSearchRefreshInterval' ); |
72 | $jobs = []; |
73 | foreach ( $titleKeys as $titleKey ) { |
74 | $title = Title::newFromDBkey( $titleKey ); |
75 | if ( !$title || !$title->canExist() ) { |
76 | continue; |
77 | } |
78 | // If possible, delay the job execution by a few seconds so Elasticsearch |
79 | // can refresh to contain what we just sent it. The delay should be long |
80 | // enough for Elasticsearch to complete the refresh cycle, which normally |
81 | // takes wgCirrusSearchRefreshInterval seconds but we double it and add |
82 | // one just in case. |
83 | $delay = 2 * $refreshInterval + 1; |
84 | $jobs[] = new IncomingLinkCount( $title, [ |
85 | 'cluster' => $this->params['cluster'], |
86 | ] + self::buildJobDelayOptions( IncomingLinkCount::class, $delay ) ); |
87 | } |
88 | MediaWikiServices::getInstance()->getJobQueueGroup()->push( $jobs ); |
89 | } |
90 | |
91 | /** |
92 | * @return bool Is this job prioritized? |
93 | */ |
94 | public function isPrioritized() { |
95 | return isset( $this->params[ 'prioritize' ] ) && $this->params[ 'prioritize' ]; |
96 | } |
97 | } |