Homestyx hydra

R1:5d1359d78f66

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…
Repository: R1 hydra
Commit Date: Sep 28 2016