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) { if (!$project) {
return new Aphront404Response(); return new Aphront404Response();
} }
$profile = $project->loadProfile();
if (empty($profile)) {
$profile = new PhabricatorProjectProfile();
}
$member_phids = $project->getMemberPHIDs(); $member_phids = $project->getMemberPHIDs();

View file

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

View file

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

View file

@ -16,6 +16,7 @@ final class PhabricatorProjectQuery
const STATUS_ARCHIVED = 'status-archived'; const STATUS_ARCHIVED = 'status-archived';
private $needMembers; private $needMembers;
private $needProfiles;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -47,6 +48,11 @@ final class PhabricatorProjectQuery
return $this; return $this;
} }
public function needProfiles($need_profiles) {
$this->needProfiles = $need_profiles;
return $this;
}
protected function getPagingColumn() { protected function getPagingColumn() {
return 'name'; return 'name';
} }
@ -108,6 +114,21 @@ final class PhabricatorProjectQuery
($row['viewerIsMember'] !== null)); ($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; return $projects;

View file

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

View file

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