- if ( $params['sort'] == 'timestamp' )
- $this->addWhereRange( 'cl_timestamp', ( $params['dir'] == 'asc' ? 'newer' : 'older' ), $params['start'], $params['end'] );
- else
- {
- $this->addWhereRange( 'cl_sortkey', ( $params['dir'] == 'asc' ? 'newer' : 'older' ), $params['startsortkey'], $params['endsortkey'] );
- $this->addWhereRange( 'cl_from', ( $params['dir'] == 'asc' ? 'newer' : 'older' ), null, null );
+
+ $dir = $params['dir'] == 'asc' ? 'newer' : 'older';
+
+ if ( $params['sort'] == 'timestamp' ) {
+ $this->addWhereRange( 'cl_timestamp',
+ $dir,
+ $params['start'],
+ $params['end'] );
+
+ $this->addOption( 'USE INDEX', 'cl_timestamp' );
+ } else {
+ if ( $params['continue'] ) {
+ $cont = explode( '|', $params['continue'], 3 );
+ if ( count( $cont ) != 3 ) {
+ $this->dieUsage( 'Invalid continue param. You should pass the original value returned '.
+ 'by the previous query', '_badcontinue'
+ );
+ }
+
+ // Remove the types to skip from $queryTypes
+ $contTypeIndex = array_search( $cont[0], $queryTypes );
+ $queryTypes = array_slice( $queryTypes, $contTypeIndex );
+
+ // Add a WHERE clause for sortkey and from
+ // pack( "H*", $foo ) is used to convert hex back to binary
+ $escSortkey = $this->getDB()->addQuotes( pack( "H*", $cont[1] ) );
+ $from = intval( $cont[2] );
+ $op = $dir == 'newer' ? '>' : '<';
+ // $contWhere is used further down
+ $contWhere = "cl_sortkey $op $escSortkey OR " .
+ "(cl_sortkey = $escSortkey AND " .
+ "cl_from $op= $from)";
+
+ } else {
+ // The below produces ORDER BY cl_sortkey, cl_from, possibly with DESC added to each of them
+ $this->addWhereRange( 'cl_sortkey',
+ $dir,
+ $params['startsortkey'],
+ $params['endsortkey'] );
+ $this->addWhereRange( 'cl_from', $dir, null, null );
+ }
+ $this->addOption( 'USE INDEX', 'cl_sortkey' );