/**
* Get the backlinks for a given table. Cached in process memory only.
- * @param string $table
+ * @param $table String
+ * @param $startId Integer or false
+ * @param $endId Integer or false
* @return TitleArray
*/
public function getLinks( $table, $startId = false, $endId = false ) {
wfProfileIn( __METHOD__ );
+ $fromField = $this->getPrefix( $table ) . '_from';
if ( $startId || $endId ) {
// Partial range, not cached
wfDebug( __METHOD__.": from DB (uncacheable range)\n" );
$conds = $this->getConditions( $table );
// Use the from field in the condition rather than the joined page_id,
// because databases are stupid and don't necessarily propagate indexes.
- $fromField = $this->getPrefix( $table ) . '_from';
if ( $startId ) {
$conds[] = "$fromField >= " . intval( $startId );
}
$conds[] = "$fromField <= " . intval( $endId );
}
$res = $this->getDB()->select(
- array( 'page', $table ),
- array( 'page_namespace', 'page_title', 'page_id' ),
+ array( $table, 'page' ),
+ array( 'page_namespace', 'page_title', 'page_id'),
$conds,
- __METHOD__ );
+ __METHOD__,
+ array(
+ 'STRAIGHT_JOIN',
+ 'ORDER BY' => $fromField
+ ) );
$ta = TitleArray::newFromResult( $res );
wfProfileOut( __METHOD__ );
return $ta;
if ( !isset( $this->fullResultCache[$table] ) ) {
wfDebug( __METHOD__.": from DB\n" );
$res = $this->getDB()->select(
- array( 'page', $table ),
+ array( $table, 'page' ),
array( 'page_namespace', 'page_title', 'page_id' ),
$this->getConditions( $table ),
- __METHOD__ );
+ __METHOD__,
+ array(
+ 'STRAIGHT_JOIN',
+ 'ORDER BY' => $fromField,
+ ) );
$this->fullResultCache[$table] = $res;
}
$ta = TitleArray::newFromResult( $this->fullResultCache[$table] );
* Returns an array giving the start and end of each range. The first batch has
* a start of false, and the last batch has an end of false.
*
- * @param string $table The links table name
- * @param integer $batchSize
- * @return array
+ * @param $table String: the links table name
+ * @param $batchSize Integer
+ * @return Array
*/
public function partition( $table, $batchSize ) {
// Try cache
$row = $res->fetchObject();
$end = $row->page_id - 1;
}
+
+ # Sanity check order
+ if ( $start && $end && $start > $end ) {
+ throw new MWException( __METHOD__.': Internal error: query result out of order' );
+ }
+
$batches[] = array( $start, $end );
}
return array( 'numRows' => $numRows, 'batches' => $batches );