mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 07:12:41 +01:00
Allow edge query filtering by destination PHIDs
Summary: See title. Adds features needed for D3136. Test Plan: Observe sanity (or run D3136 in a sandbox and observe that voting works). Reviewers: epriestley Reviewed By: epriestley CC: gmarcotte, aran, Korvin Differential Revision: https://secure.phabricator.com/D3205
This commit is contained in:
parent
eeb359bae6
commit
9debf779d6
1 changed files with 47 additions and 0 deletions
|
@ -38,6 +38,7 @@
|
|||
final class PhabricatorEdgeQuery extends PhabricatorQuery {
|
||||
|
||||
private $sourcePHIDs;
|
||||
private $destPHIDs;
|
||||
private $edgeTypes;
|
||||
private $resultSet;
|
||||
|
||||
|
@ -62,6 +63,19 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find edges terminating at one or more destination PHIDs.
|
||||
*
|
||||
* @param list List of destination PHIDs.
|
||||
* @return this
|
||||
*
|
||||
*/
|
||||
public function withDestinationPHIDs(array $dest_phids) {
|
||||
$this->destPHIDs = $dest_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find edges of specific types.
|
||||
*
|
||||
|
@ -110,6 +124,31 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery {
|
|||
return array_keys($edges[$src_phid][$edge_type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for loading a single edge's metadata for
|
||||
* a given source, destination, and edge type. Returns null
|
||||
* if the edge does not exist or does not have metadata. Builds
|
||||
* and immediately executes a full query.
|
||||
*
|
||||
* @param phid Source PHID.
|
||||
* @param const Edge type.
|
||||
* @param phid Destination PHID.
|
||||
* @return wild Edge annotation (or null).
|
||||
*/
|
||||
public static function loadSingleEdgeData($src_phid, $edge_type, $dest_phid) {
|
||||
$edges = id(new PhabricatorEdgeQuery())
|
||||
->withSourcePHIDs(array($src_phid))
|
||||
->withEdgeTypes(array($edge_type))
|
||||
->withDestinationPHIDs(array($dest_phid))
|
||||
->needEdgeData(true)
|
||||
->execute();
|
||||
|
||||
if (isset($edges[$src_phid][$edge_type][$dest_phid]['data'])) {
|
||||
return $edges[$src_phid][$edge_type][$dest_phid]['data'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load specified edges.
|
||||
|
@ -262,6 +301,14 @@ final class PhabricatorEdgeQuery extends PhabricatorQuery {
|
|||
$this->edgeTypes);
|
||||
}
|
||||
|
||||
if ($this->destPHIDs) {
|
||||
// potentially complain if $this->edgeType was not set
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'edge.dst IN (%Ls)',
|
||||
$this->destPHIDs);
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue