X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FpurgeChangedPages.php;h=81fb5e39d7a5852289a7e6ba6b77150452a3293d;hb=4d6828ef7835b7c5c5e903637fcba4bf5c487e1b;hp=0ef2a999f47720aae7fbf36b33103efba563350a;hpb=787da207a297714551fec2e518d67fbe3e957d60;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/purgeChangedPages.php b/maintenance/purgeChangedPages.php index 0ef2a999f4..81fb5e39d7 100644 --- a/maintenance/purgeChangedPages.php +++ b/maintenance/purgeChangedPages.php @@ -170,23 +170,31 @@ class PurgeChangedPages extends Maintenance { */ protected function pageableSortedRows( ResultWrapper $res, $column, $limit ) { $rows = iterator_to_array( $res, false ); - $count = count( $rows ); - if ( !$count ) { - return [ [], null ]; // nothing to do - } elseif ( $count < $limit ) { - return [ $rows, $rows[$count - 1]->$column ]; // no more rows left + + // Nothing to do + if ( !$rows ) { + return [ [], null ]; + } + + $lastValue = end( $rows )->$column; + if ( count( $rows ) < $limit ) { + return [ $rows, $lastValue ]; } - $lastValue = $rows[$count - 1]->$column; // should be the highest - for ( $i = $count - 1; $i >= 0; --$i ) { - if ( $rows[$i]->$column === $lastValue ) { - unset( $rows[$i] ); - } else { + + for ( $i = count( $rows ) - 1; $i >= 0; --$i ) { + if ( $rows[$i]->$column !== $lastValue ) { break; } + + unset( $rows[$i] ); + } + + // No more rows left + if ( !$rows ) { + return [ [], null ]; } - $lastValueLeft = count( $rows ) ? $rows[count( $rows ) - 1]->$column : null; - return [ $rows, $lastValueLeft ]; + return [ $rows, end( $rows )->$column ]; } }