@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+14 -12
+14 -12
src/applications/system/engine/PhabricatorSystemActionEngine.php
··· 100 100 101 101 $actor_hashes = array(); 102 102 foreach ($actors as $actor) { 103 - $actor_hashes[] = PhabricatorHash::digestForIndex($actor); 103 + $digest = PhabricatorHash::digestForIndex($actor); 104 + $actor_hashes[$digest] = $actor; 104 105 } 105 106 106 107 $log = new PhabricatorSystemActionLog(); 107 108 108 109 $window = self::getWindow(); 109 110 110 - $conn_r = $log->establishConnection('r'); 111 - $scores = queryfx_all( 112 - $conn_r, 113 - 'SELECT actorIdentity, SUM(score) totalScore FROM %T 111 + $conn = $log->establishConnection('r'); 112 + 113 + $rows = queryfx_all( 114 + $conn, 115 + 'SELECT actorHash, SUM(score) totalScore FROM %T 114 116 WHERE action = %s AND actorHash IN (%Ls) 115 117 AND epoch >= %d GROUP BY actorHash', 116 118 $log->getTableName(), 117 119 $action->getActionConstant(), 118 - $actor_hashes, 119 - (time() - $window)); 120 + array_keys($actor_hashes), 121 + (PhabricatorTime::getNow() - $window)); 120 122 121 - $scores = ipull($scores, 'totalScore', 'actorIdentity'); 123 + $rows = ipull($rows, 'totalScore', 'actorHash'); 122 124 123 - foreach ($scores as $key => $score) { 124 - $scores[$key] = $score / $window; 125 + $scores = array(); 126 + foreach ($actor_hashes as $digest => $actor) { 127 + $score = idx($rows, $digest, 0); 128 + $scores[$actor] = ($score / $window); 125 129 } 126 - 127 - $scores = $scores + array_fill_keys($actors, 0); 128 130 129 131 return $scores; 130 132 }