* of memory.
*
* Introduced by r47317
- *
- * @internal documentation reviewed on 18 Mar 2011 by hashar
*/
class BacklinkCache {
/** @var ProcessCacheLRU */
* @since 1.25
*/
public function getCascadeProtectedLinks() {
- // This method is used to make redudant jobs anyway, so its OK to use
- // a slave. Also, the set of cascade protected pages tends to be stable.
$dbr = $this->getDB();
- $queries = array();
- // @note: UNION filters any duplicate pages
- $queries[] = $dbr->selectSQLText(
+ // @todo: use UNION without breaking tests that use temp tables
+ $resSets = array();
+ $resSets[] = $dbr->select(
array( 'templatelinks', 'page_restrictions', 'page' ),
array( 'page_namespace', 'page_title', 'page_id' ),
array(
'tl_from = pr_page',
'pr_cascade' => 1,
'page_id = tl_from'
- )
- );
- $queries[] = $dbr->selectSQLText(
- array( 'imagelinks', 'page_restrictions', 'page' ),
- array( 'page_namespace', 'page_title', 'page_id' ),
- array(
- 'il_to' => $this->title->getDBkey(),
- 'il_from = pr_page',
- 'pr_cascade' => 1,
- 'page_id = il_from'
- )
+ ),
+ __METHOD__,
+ array( 'DISTINCT' )
);
+ if ( $this->title->getNamespace() == NS_FILE ) {
+ $resSets[] = $dbr->select(
+ array( 'imagelinks', 'page_restrictions', 'page' ),
+ array( 'page_namespace', 'page_title', 'page_id' ),
+ array(
+ 'il_to' => $this->title->getDBkey(),
+ 'il_from = pr_page',
+ 'pr_cascade' => 1,
+ 'page_id = il_from'
+ ),
+ __METHOD__,
+ array( 'DISTINCT' )
+ );
+ }
+
+ // Combine and de-duplicate the results
+ $mergedRes = array();
+ foreach ( $resSets as $res ) {
+ foreach ( $res as $row ) {
+ $mergedRes[$row->page_id] = $row;
+ }
+ }
- return TitleArray::newFromResult( $dbr->query(
- $dbr->unionQueries( $queries, false ),
- __METHOD__
- ) );
+ return TitleArray::newFromResult(
+ new FakeResultWrapper( array_values( $mergedRes ) ) );
}
}