1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02: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) {
$results = array();
$projects = id(new ReleephProject())->loadAllWhere('isActive = 1');
$projects = id(new ReleephProjectQuery())
->setViewer($request->getUser())
->withActive(1)
->execute();
foreach ($projects as $project) {
$repository = $project->loadOneRelative(
id(new PhabricatorRepository()),
'id',
'getRepositoryID');
$repository = $project->getRepository();
$branches = $project->loadRelatives(
id(new ReleephBranch()),

View file

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

View file

@ -7,6 +7,8 @@ final class ReleephProjectQuery
private $ids;
private $phids;
private $needRepositories;
private $order = 'order-id';
const ORDER_ID = 'order-id';
const ORDER_NAME = 'order-name';
@ -46,6 +48,29 @@ final class ReleephProjectQuery
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) {
$where = array();
@ -53,7 +78,7 @@ final class ReleephProjectQuery
$where[] = qsprintf(
$conn_r,
'isActive = %d',
$this->active);
(int)$this->active);
}
if ($this->ids) {

View file

@ -27,6 +27,8 @@ final class ReleephProject extends ReleephDAO
protected $details = array();
private $repository = self::ATTACHABLE;
public function getConfiguration() {
return array(
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() {
return $this->loadOneRelative(
new PhabricatorRepository(),
'id',
'getRepositoryID');
'phid',
'getRepositoryPHID');
}
public function getCurrentReleaseNumber() {