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

Remove all reads of ReleephProject->repositoryID

Summary:
Ref T3655. ReleephProject currently has both `repositoryID` and `repositoryPHID`, which point to the same object and are reudundant. Get rid of all reads of `repositoryID`.

NOTE: This makes project loads depend on repository loads. The eventual rule here will be that you must be able to see a repository in order to see projects for that repository, which seems like a reasonable rule. We might need to tailor it more than this (e.g., if there are branch read permissions down the line) but this seems like a reasonable minimum.

Test Plan: Grepped for `repositoryID` in `releeph/`. Called `releeph.getbranches`.

Reviewers: btrahan

Reviewed By: btrahan

CC: LegNeato, aran

Maniphest Tasks: T3655

Differential Revision: https://secure.phabricator.com/D6633
This commit is contained in:
epriestley 2013-08-14 08:59:28 -07:00
parent c8061d5da8
commit a7955e919c
4 changed files with 53 additions and 20 deletions

View file

@ -24,13 +24,13 @@ final class ConduitAPI_releeph_getbranches_Method
protected function execute(ConduitAPIRequest $request) { protected function execute(ConduitAPIRequest $request) {
$results = array(); $results = array();
$projects = id(new ReleephProject())->loadAllWhere('isActive = 1'); $projects = id(new ReleephProjectQuery())
->setViewer($request->getUser())
->withActive(1)
->execute();
foreach ($projects as $project) { foreach ($projects as $project) {
$repository = $project->loadOneRelative( $repository = $project->getRepository();
id(new PhabricatorRepository()),
'id',
'getRepositoryID');
$branches = $project->loadRelatives( $branches = $project->loadRelatives(
id(new ReleephBranch()), id(new ReleephBranch()),

View file

@ -69,18 +69,14 @@ final class ReleephProjectListController extends ReleephController
->setHref($enable_uri)); ->setHref($enable_uri));
} }
// TODO: See T3551. $repo = $project->getRepository();
$item->addAttribute(
$repo = $project->loadPhabricatorRepository(); phutil_tag(
if ($repo) { 'a',
$item->addAttribute( array(
phutil_tag( 'href' => '/diffusion/'.$repo->getCallsign().'/',
'a', ),
array( 'r'.$repo->getCallsign()));
'href' => '/diffusion/'.$repo->getCallsign().'/',
),
'r'.$repo->getCallsign()));
}
$arc = $project->loadArcanistProject(); $arc = $project->loadArcanistProject();
if ($arc) { if ($arc) {

View file

@ -7,6 +7,8 @@ final class ReleephProjectQuery
private $ids; private $ids;
private $phids; private $phids;
private $needRepositories;
private $order = 'order-id'; private $order = 'order-id';
const ORDER_ID = 'order-id'; const ORDER_ID = 'order-id';
const ORDER_NAME = 'order-name'; const ORDER_NAME = 'order-name';
@ -46,6 +48,29 @@ final class ReleephProjectQuery
return $table->loadAllFromArray($rows); return $table->loadAllFromArray($rows);
} }
public function willFilterPage(array $projects) {
assert_instances_of($projects, 'ReleephProject');
$repository_phids = mpull($projects, 'getRepositoryPHID');
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($this->getViewer())
->withPHIDs($repository_phids)
->execute();
$repositories = mpull($repositories, null, 'getPHID');
foreach ($projects as $key => $project) {
$repo = idx($repositories, $project->getRepositoryPHID());
if (!$repo) {
unset($projects[$key]);
continue;
}
$project->attachRepository($repo);
}
return $projects;
}
private function buildWhereClause(AphrontDatabaseConnection $conn_r) { private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array(); $where = array();
@ -53,7 +78,7 @@ final class ReleephProjectQuery
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'isActive = %d', 'isActive = %d',
$this->active); (int)$this->active);
} }
if ($this->ids) { if ($this->ids) {

View file

@ -27,6 +27,8 @@ final class ReleephProject extends ReleephDAO
protected $details = array(); protected $details = array();
private $repository = self::ATTACHABLE;
public function getConfiguration() { public function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
@ -111,11 +113,21 @@ final class ReleephProject extends ReleephDAO
} }
} }
public function attachRepository(PhabricatorRepository $repository) {
$this->repository = $repository;
return $this;
}
public function getRepository() {
return $this->assertAttached($this->repository);
}
// TODO: Remove once everything uses ProjectQuery.
public function loadPhabricatorRepository() { public function loadPhabricatorRepository() {
return $this->loadOneRelative( return $this->loadOneRelative(
new PhabricatorRepository(), new PhabricatorRepository(),
'id', 'phid',
'getRepositoryID'); 'getRepositoryPHID');
} }
public function getCurrentReleaseNumber() { public function getCurrentReleaseNumber() {