aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/TableCleanup.php
diff options
context:
space:
mode:
authorBartosz Dziewoński <matma.rex@gmail.com>2022-09-04 00:48:19 +0200
committerBartosz Dziewoński <matma.rex@gmail.com>2022-09-10 04:22:19 +0200
commitec79aa394312d62b598ad29601e2c80eaaf0dd19 (patch)
tree7218ca927c1945bb252892370d3d2991a3585d67 /maintenance/TableCleanup.php
parentaf60bf699c7de2b52fef6cd66e79b151a9f81ab8 (diff)
downloadmediawikicore-ec79aa394312d62b598ad29601e2c80eaaf0dd19.tar.gz
mediawikicore-ec79aa394312d62b598ad29601e2c80eaaf0dd19.zip
SQLPlatform: Introduce buildComparison()
Builds a condition comparing multiple values, for use with indexes that cover multiple fields, common when e.g. paging through results or doing batch operations. Can also be to generate a simple comparison without writing raw SQL (see T210206). Update a few manually constructed conditions to use this method. There are more maintenance scripts and API classes that use the same patterns, but this is a start. As you can see by the code I'm replacing, there are many ways to do this. I picked the one used by maintenance/TableCleanup.php, since I found it the easiest to understand. Change-Id: Ic368a87fb5ce4c13608b03206cd68518ec9732d4
Diffstat (limited to 'maintenance/TableCleanup.php')
-rw-r--r--maintenance/TableCleanup.php16
1 files changed, 4 insertions, 12 deletions
diff --git a/maintenance/TableCleanup.php b/maintenance/TableCleanup.php
index 53bc915c9e14..779f7c9f84af 100644
--- a/maintenance/TableCleanup.php
+++ b/maintenance/TableCleanup.php
@@ -148,20 +148,12 @@ class TableCleanup extends Maintenance {
}
// Update the conditions to select the next batch.
- // Construct a condition string by starting with the least significant part
- // of the index, and adding more significant parts progressively to the left
- // of the string.
- $nextCond = '';
- foreach ( array_reverse( $index ) as $field ) {
+ $conds = [];
+ foreach ( $index as $field ) {
// @phan-suppress-next-line PhanPossiblyUndeclaredVariable $res has at at least one item
- $encValue = $dbr->addQuotes( $row->$field );
- if ( $nextCond === '' ) {
- $nextCond = "$field > $encValue";
- } else {
- $nextCond = "$field > $encValue OR ($field = $encValue AND ($nextCond))";
- }
+ $conds[ $field ] = $row->$field;
}
- $indexConds = [ $nextCond ];
+ $indexConds = [ $dbr->buildComparison( '>', $conds ) ];
}
$this->output( "Finished $table... $this->updated of $this->processed rows updated\n" );