mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 07:20:57 +01:00
Fix "ONLY_FULL_GROUP_BY" issue in SystemAction queries
Summary: Ref T13404. This query is invalid under "sql_mode=ONLY_FULL_GROUP_BY". Rewrite it to avoid interacting with `actorIdentity` at all; this is a little more robust in the presence of weird data and not really more complicated. Test Plan: - Enabled "ONLY_FULL_GROUP_BY". - Hit system actions (e.g., login). - Before: error. - After: clean login. - Tried to login with a bad password many times in a row, got properly limited by the system action rate limiter. Maniphest Tasks: T13404 Differential Revision: https://secure.phabricator.com/D20782
This commit is contained in:
parent
e0d6994adb
commit
22b075df97
1 changed files with 14 additions and 12 deletions
|
@ -100,32 +100,34 @@ final class PhabricatorSystemActionEngine extends Phobject {
|
|||
|
||||
$actor_hashes = array();
|
||||
foreach ($actors as $actor) {
|
||||
$actor_hashes[] = PhabricatorHash::digestForIndex($actor);
|
||||
$digest = PhabricatorHash::digestForIndex($actor);
|
||||
$actor_hashes[$digest] = $actor;
|
||||
}
|
||||
|
||||
$log = new PhabricatorSystemActionLog();
|
||||
|
||||
$window = self::getWindow();
|
||||
|
||||
$conn_r = $log->establishConnection('r');
|
||||
$scores = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT actorIdentity, SUM(score) totalScore FROM %T
|
||||
$conn = $log->establishConnection('r');
|
||||
|
||||
$rows = queryfx_all(
|
||||
$conn,
|
||||
'SELECT actorHash, SUM(score) totalScore FROM %T
|
||||
WHERE action = %s AND actorHash IN (%Ls)
|
||||
AND epoch >= %d GROUP BY actorHash',
|
||||
$log->getTableName(),
|
||||
$action->getActionConstant(),
|
||||
$actor_hashes,
|
||||
(time() - $window));
|
||||
array_keys($actor_hashes),
|
||||
(PhabricatorTime::getNow() - $window));
|
||||
|
||||
$scores = ipull($scores, 'totalScore', 'actorIdentity');
|
||||
$rows = ipull($rows, 'totalScore', 'actorHash');
|
||||
|
||||
foreach ($scores as $key => $score) {
|
||||
$scores[$key] = $score / $window;
|
||||
$scores = array();
|
||||
foreach ($actor_hashes as $digest => $actor) {
|
||||
$score = idx($rows, $digest, 0);
|
||||
$scores[$actor] = ($score / $window);
|
||||
}
|
||||
|
||||
$scores = $scores + array_fill_keys($actors, 0);
|
||||
|
||||
return $scores;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue