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

(stable) Fix an issue with the Herald engine field value cache

Summary:
To improve the performance of Herald, we attempt to generate the value for each field (e.g., a task title) only once.

For most field values this is cheap, but for some (like a commit's branches) it can be quite expensive. We only want to pay this cost once, so we cache field values.

However, D12957 accidentally added a check where we bypass the cache and generate the value for every field, before reading the cache. This causes us to generate each field for every rule that uses it, plus one extra time.

Instead, use the cache for this check, too. Also allow the cache to cache `null`, since it can be expensive to generate `null` even though the value isn't too interesting.

The value of this early hit isn't even used (we only care if it throws or not).

Test Plan:
  - Wrote a rule like "if any condition matches: branches contain a, branches contain b, branches contain c".
  - Put `phlog(new Exception())` in `DiffusionCommitBranchesHeraldField`.
  - Before patch, saw `bin/repository reparse --herald <any commit>` compute branches three times.
  - After patch, saw only one computation.
  - Verified field values in the transcript view

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D15451
This commit is contained in:
epriestley 2016-03-09 10:17:40 -08:00
parent 2c67d9c8ac
commit 8b56e0082b

View file

@ -274,7 +274,7 @@ final class HeraldEngine extends Phobject {
} else { } else {
foreach ($conditions as $condition) { foreach ($conditions as $condition) {
try { try {
$object->getHeraldField($condition->getFieldName()); $this->getConditionObjectValue($condition, $object);
} catch (Exception $ex) { } catch (Exception $ex) {
$reason = pht( $reason = pht(
'Field "%s" does not exist!', 'Field "%s" does not exist!',
@ -366,14 +366,11 @@ final class HeraldEngine extends Phobject {
} }
public function getObjectFieldValue($field) { public function getObjectFieldValue($field) {
if (isset($this->fieldCache[$field])) { if (!array_key_exists($field, $this->fieldCache)) {
return $this->fieldCache[$field]; $this->fieldCache[$field] = $this->object->getHeraldField($field);
} }
$result = $this->object->getHeraldField($field); return $this->fieldCache[$field];
$this->fieldCache[$field] = $result;
return $result;
} }
protected function getRuleEffects( protected function getRuleEffects(