Changeset View
Changeset View
Standalone View
Standalone View
src/applications/system/engine/PhabricatorSystemActionEngine.php
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | public static function loadScores( | ||||
PhabricatorSystemAction $action) { | PhabricatorSystemAction $action) { | ||||
if (!$actors) { | if (!$actors) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$actor_hashes = array(); | $actor_hashes = array(); | ||||
foreach ($actors as $actor) { | foreach ($actors as $actor) { | ||||
$actor_hashes[] = PhabricatorHash::digestForIndex($actor); | $digest = PhabricatorHash::digestForIndex($actor); | ||||
$actor_hashes[$digest] = $actor; | |||||
} | } | ||||
$log = new PhabricatorSystemActionLog(); | $log = new PhabricatorSystemActionLog(); | ||||
$window = self::getWindow(); | $window = self::getWindow(); | ||||
$conn_r = $log->establishConnection('r'); | $conn = $log->establishConnection('r'); | ||||
$scores = queryfx_all( | |||||
$conn_r, | $rows = queryfx_all( | ||||
'SELECT actorIdentity, SUM(score) totalScore FROM %T | $conn, | ||||
'SELECT actorHash, SUM(score) totalScore FROM %T | |||||
WHERE action = %s AND actorHash IN (%Ls) | WHERE action = %s AND actorHash IN (%Ls) | ||||
AND epoch >= %d GROUP BY actorHash', | AND epoch >= %d GROUP BY actorHash', | ||||
$log->getTableName(), | $log->getTableName(), | ||||
$action->getActionConstant(), | $action->getActionConstant(), | ||||
$actor_hashes, | array_keys($actor_hashes), | ||||
(time() - $window)); | (PhabricatorTime::getNow() - $window)); | ||||
$scores = ipull($scores, 'totalScore', 'actorIdentity'); | $rows = ipull($rows, 'totalScore', 'actorHash'); | ||||
foreach ($scores as $key => $score) { | $scores = array(); | ||||
$scores[$key] = $score / $window; | foreach ($actor_hashes as $digest => $actor) { | ||||
$score = idx($rows, $digest, 0); | |||||
$scores[$actor] = ($score / $window); | |||||
} | } | ||||
$scores = $scores + array_fill_keys($actors, 0); | |||||
return $scores; | return $scores; | ||||
} | } | ||||
private static function recordAction( | private static function recordAction( | ||||
array $actors, | array $actors, | ||||
PhabricatorSystemAction $action, | PhabricatorSystemAction $action, | ||||
$score) { | $score) { | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |