1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Fix an issue where repository message counts would never reset

Summary:
Fixes T11705. I did not realize that `ON DUPLICATE KEY UPDATE` was order-dependent, so the "reset" clause of this `IF(...)` never actually worked.

Reorder it so we check if we're changing the message type //first//, then actually change the message type.

This makes the count reset properly when a failing repository succeeds, or a working repository fails.

Test Plan:
  - On `master`, forced a working repository to fail a `bin/repository update`, saw the message change types (expected) but keep the old count (wrong!).
  - With this patch, repeated the process and saw the count reset properly.
  - Ran the patch, verified counts reset to 0.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11705

Differential Revision: https://secure.phabricator.com/D16623
This commit is contained in:
epriestley 2016-09-28 14:49:30 -07:00
parent 360597d8ee
commit 5d1359d78f
2 changed files with 15 additions and 7 deletions

View file

@ -0,0 +1,4 @@
/* Reset message counts to fix the bug in T11705 which caused some of them to
become very large. */
UPDATE {$NAMESPACE}_repository.repository_statusmessage
SET messageCount = 0;

View file

@ -1651,8 +1651,12 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
} else { } else {
// If the existing message has the same code (e.g., we just hit an // If the existing message has the same code (e.g., we just hit an
// error and also previously hit an error) we increment the message // error and also previously hit an error) we increment the message
// count by 1. This allows us to determine how many times in a row // count. This allows us to determine how many times in a row we've
// we've run into an error. // run into an error.
// NOTE: The assignments in "ON DUPLICATE KEY UPDATE" are evaluated
// in order, so the "messageCount" assignment must occur before the
// "statusCode" assignment. See T11705.
queryfx( queryfx(
$conn_w, $conn_w,
@ -1661,14 +1665,14 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
messageCount) messageCount)
VALUES (%d, %s, %s, %s, %d, %d) VALUES (%d, %s, %s, %s, %d, %d)
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
statusCode = VALUES(statusCode),
parameters = VALUES(parameters),
epoch = VALUES(epoch),
messageCount = messageCount =
IF( IF(
statusCode = VALUES(statusCode), statusCode = VALUES(statusCode),
messageCount + 1, messageCount + VALUES(messageCount),
VALUES(messageCount))', VALUES(messageCount)),
statusCode = VALUES(statusCode),
parameters = VALUES(parameters),
epoch = VALUES(epoch)',
$table_name, $table_name,
$this->getID(), $this->getID(),
$status_type, $status_type,