Fix GREATEST usage in site_stats

For the positive-delta case since the row can't be negative the
`GREATEST` is useless, so delete it. For the negative-delta case do the
GREATEST before the subtraction so that it doesn't try to temporarily go
negative.

Bug: T315573
Change-Id: I0a27a57835048ee6a06266d377ed8f3f52ddf435
(cherry picked from commit 4017d2b6d60c6eb5c02ca48c8d8eeb74a18ba262)
This commit is contained in:
Pppery 2025-03-19 22:59:18 -04:00 committed by Reedy
parent 46ac6adf85
commit b9c99fc622

View file

@ -138,16 +138,13 @@ class SiteStatsUpdate implements DeferrableUpdate, MergeableUpdate {
$delta = (int)$deltaByType[$type];
$initValues[$field] = $delta;
if ( $delta > 0 ) {
$set[$field] = new RawSQLValue( $dbw->buildGreatest(
[ $field => $dbw->addIdentifierQuotes( $field ) . '+' . abs( $delta ) ],
0
) );
$set[$field] = new RawSQLValue( $dbw->addIdentifierQuotes( $field ) . '+' . abs( $delta ) );
} elseif ( $delta < 0 ) {
$hasNegativeDelta = true;
$set[$field] = new RawSQLValue( $dbw->buildGreatest(
[ 'new' => $dbw->addIdentifierQuotes( $field ) . '-' . abs( $delta ) ],
0
) );
[ 'new' => $dbw->addIdentifierQuotes( $field ) ],
abs( $delta )
) . '-' . abs( $delta ) );
}
}