Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/edges/query/PhabricatorEdgeQuery.php
Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | /* -( Executing the Query )------------------------------------------------ */ | ||||
public function getDestinationPHIDs( | public function getDestinationPHIDs( | ||||
array $src_phids = array(), | array $src_phids = array(), | ||||
array $types = array()) { | array $types = array()) { | ||||
if ($this->resultSet === null) { | if ($this->resultSet === null) { | ||||
throw new Exception( | throw new Exception( | ||||
'You must execute() a query before you you can getDestinationPHIDs().'); | 'You must execute() a query before you you can getDestinationPHIDs().'); | ||||
} | } | ||||
$src_phids = array_fill_keys($src_phids, true); | |||||
$types = array_fill_keys($types, true); | |||||
$result_phids = array(); | $result_phids = array(); | ||||
foreach ($this->resultSet as $src => $edges_by_type) { | |||||
if ($src_phids && empty($src_phids[$src])) { | $set = $this->resultSet; | ||||
continue; | if ($src_phids) { | ||||
} | $set = array_select_keys($set, $src_phids); | ||||
foreach ($edges_by_type as $type => $edges_by_dst) { | |||||
if ($types && empty($types[$type])) { | |||||
continue; | |||||
} | } | ||||
foreach ($edges_by_dst as $dst => $edge) { | |||||
$result_phids[$dst] = true; | foreach ($set as $src => $edges_by_type) { | ||||
if ($types) { | |||||
$edges_by_type = array_select_keys($edges_by_type, $types); | |||||
} | } | ||||
foreach ($edges_by_type as $edge) { | |||||
$result_phids = array_mergev(array($result_phids, $edge)); | |||||
epriestley: Oh, sorry -- `array_mergev()` in a loop is just as bad as `array_merge()`, it just simplifies… | |||||
} | } | ||||
} | } | ||||
return array_keys($result_phids); | return array_keys($result_phids); | ||||
} | } | ||||
Not Done Inline ActionsThis can produce very bad performance behavior -- the cost of array_merge() is approximately the size of all the arguments combined, so when you repeatedly merge a small addition into a large existing array the overall runtime approaches O(N^2). Some discussion here: https://secure.phabricator.com/book/phabflavor/article/php_pitfalls/#array-merge-in-incredibl epriestley: This can produce very bad performance behavior -- the cost of `array_merge()` is approximately… | |||||
/* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
/** | /** | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
private function buildWhereClause($conn_r) { | private function buildWhereClause($conn_r) { | ||||
Show All 40 Lines |
Oh, sorry -- array_mergev() in a loop is just as bad as array_merge(), it just simplifies this:
Otherwise the last line would need to be:
...which is way more cumbersome. But it's equivalent, and just calls array_merge() internally.
Just keep this like it was, I think?