Conditions | 5 |
Paths | 7 |
Total Lines | 55 |
Code Lines | 26 |
Lines | 12 |
Ratio | 21.82 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
96 | protected function invalidateTitles( array $pages ) { |
||
97 | global $wgUpdateRowsPerQuery, $wgUseFileCache; |
||
98 | |||
99 | // Get all page IDs in this query into an array |
||
100 | $pageIds = array_keys( $pages ); |
||
101 | if ( !$pageIds ) { |
||
102 | return; |
||
103 | } |
||
104 | |||
105 | // Bump page_touched to the current timestamp. This used to use the root job timestamp |
||
106 | // (e.g. template/file edit time), which was a bit more efficient when template edits are |
||
107 | // rare and don't effect the same pages much. However, this way allows for better |
||
108 | // de-duplication, which is much more useful for wikis with high edit rates. Note that |
||
109 | // RefreshLinksJob, which is enqueued alongside HTMLCacheUpdateJob, saves the parser output |
||
110 | // since it has to parse anyway. We assume that vast majority of the cache jobs finish |
||
111 | // before the link jobs, so using the current timestamp instead of the root timestamp is |
||
112 | // not expected to invalidate these cache entries too often. |
||
113 | $touchTimestamp = wfTimestampNow(); |
||
114 | |||
115 | $dbw = wfGetDB( DB_MASTER ); |
||
116 | $factory = wfGetLBFactory(); |
||
|
|||
117 | $ticket = $factory->getEmptyTransactionTicket( __METHOD__ ); |
||
118 | // Update page_touched (skipping pages already touched since the root job). |
||
119 | // Check $wgUpdateRowsPerQuery for sanity; batch jobs are sized by that already. |
||
120 | View Code Duplication | foreach ( array_chunk( $pageIds, $wgUpdateRowsPerQuery ) as $batch ) { |
|
121 | $factory->commitAndWaitForReplication( __METHOD__, $ticket ); |
||
122 | |||
123 | $dbw->update( 'page', |
||
124 | [ 'page_touched' => $dbw->timestamp( $touchTimestamp ) ], |
||
125 | [ 'page_id' => $batch, |
||
126 | // don't invalidated pages that were already invalidated |
||
127 | "page_touched < " . $dbw->addQuotes( $dbw->timestamp( $touchTimestamp ) ) |
||
128 | ], |
||
129 | __METHOD__ |
||
130 | ); |
||
131 | } |
||
132 | // Get the list of affected pages (races only mean something else did the purge) |
||
133 | $titleArray = TitleArray::newFromResult( $dbw->select( |
||
134 | 'page', |
||
135 | [ 'page_namespace', 'page_title' ], |
||
136 | [ 'page_id' => $pageIds, 'page_touched' => $dbw->timestamp( $touchTimestamp ) ], |
||
137 | __METHOD__ |
||
138 | ) ); |
||
139 | |||
140 | // Update CDN |
||
141 | $u = CdnCacheUpdate::newFromTitles( $titleArray ); |
||
142 | $u->doUpdate(); |
||
143 | |||
144 | // Update file cache |
||
145 | if ( $wgUseFileCache ) { |
||
146 | foreach ( $titleArray as $title ) { |
||
147 | HTMLFileCache::clearFileCache( $title ); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
156 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.