1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 13:52:40 +01:00

Remove PhabricatorProject->loadProfile

Summary: Ref T603. Do modern, sensible queries here.

Test Plan: Viewed project profile, list, member edit, profile edit, used typeahead, changed project image.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7252
This commit is contained in:
epriestley 2013-10-06 17:07:20 -07:00
parent 64e4b3aef4
commit 80f6d00940
6 changed files with 38 additions and 25 deletions

View file

@ -26,10 +26,6 @@ final class PhabricatorProjectMembersEditController
if (!$project) {
return new Aphront404Response();
}
$profile = $project->loadProfile();
if (empty($profile)) {
$profile = new PhabricatorProjectProfile();
}
$member_phids = $project->getMemberPHIDs();

View file

@ -5,7 +5,6 @@ final class PhabricatorProjectProfileController
private $id;
private $page;
private $project;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
@ -16,21 +15,17 @@ final class PhabricatorProjectProfileController
$request = $this->getRequest();
$user = $request->getUser();
$query = id(new PhabricatorProjectQuery())
$project = id(new PhabricatorProjectQuery())
->setViewer($user)
->withIDs(array($this->id))
->needMembers(true);
$project = $query->executeOne();
$this->project = $project;
->needMembers(true)
->needProfiles(true)
->executeOne();
if (!$project) {
return new Aphront404Response();
}
$profile = $project->loadProfile();
if (!$profile) {
$profile = new PhabricatorProjectProfile();
}
$profile = $project->getProfile();
$picture = $profile->loadProfileImageURI();

View file

@ -22,16 +22,13 @@ final class PhabricatorProjectProfileEditController
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->needProfiles(true)
->executeOne();
if (!$project) {
return new Aphront404Response();
}
$profile = $project->loadProfile();
if (empty($profile)) {
$profile = new PhabricatorProjectProfile();
}
$profile = $project->getProfile();
$img_src = $profile->loadProfileImageURI();
$options = PhabricatorProjectStatus::getStatusMap();

View file

@ -16,6 +16,7 @@ final class PhabricatorProjectQuery
const STATUS_ARCHIVED = 'status-archived';
private $needMembers;
private $needProfiles;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -47,6 +48,11 @@ final class PhabricatorProjectQuery
return $this;
}
public function needProfiles($need_profiles) {
$this->needProfiles = $need_profiles;
return $this;
}
protected function getPagingColumn() {
return 'name';
}
@ -108,6 +114,21 @@ final class PhabricatorProjectQuery
($row['viewerIsMember'] !== null));
}
}
if ($this->needProfiles) {
$profiles = id(new PhabricatorProjectProfile())->loadAllWhere(
'projectPHID IN (%Ls)',
mpull($projects, 'getPHID'));
$profiles = mpull($profiles, null, 'getProjectPHID');
foreach ($projects as $project) {
$profile = idx($profiles, $project->getPHID());
if (!$profile) {
$profile = id(new PhabricatorProjectProfile())
->setProjectPHID($project->getPHID());
}
$project->attachProfile($profile);
}
}
}
return $projects;

View file

@ -17,6 +17,7 @@ final class PhabricatorProject extends PhabricatorProjectDAO
private $subprojectsNeedUpdate;
private $memberPHIDs = self::ATTACHABLE;
private $sparseMembers = self::ATTACHABLE;
private $profile = self::ATTACHABLE;
public function getCapabilities() {
return array(
@ -96,11 +97,13 @@ final class PhabricatorProject extends PhabricatorProjectDAO
PhabricatorProjectPHIDTypeProject::TYPECONST);
}
public function loadProfile() {
$profile = id(new PhabricatorProjectProfile())->loadOneWhere(
'projectPHID = %s',
$this->getPHID());
return $profile;
public function getProfile() {
return $this->assertAttached($this->profile);
}
public function attachProfile(PhabricatorProjectProfile $profile) {
$this->profile = $profile;
return $this;
}
public function attachMemberPHIDs(array $phids) {

View file

@ -223,6 +223,7 @@ final class PhabricatorTypeaheadCommonDatasourceController
$projs = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withStatus(PhabricatorProjectQuery::STATUS_OPEN)
->needProfiles(true)
->execute();
foreach ($projs as $proj) {
$proj_result = id(new PhabricatorTypeaheadResult())
@ -230,7 +231,7 @@ final class PhabricatorTypeaheadCommonDatasourceController
->setDisplayType("Project")
->setURI('/project/view/'.$proj->getID().'/')
->setPHID($proj->getPHID());
$prof = $proj->loadProfile();
$prof = $proj->getProfile();
if ($prof) {
$proj_result->setImageURI($prof->loadProfileImageURI());
}