From 80f6d0094041ddb012e8f48218ff11e0d09f1a33 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 6 Oct 2013 17:07:20 -0700 Subject: [PATCH] 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 --- ...habricatorProjectMembersEditController.php | 4 ---- .../PhabricatorProjectProfileController.php | 15 +++++-------- ...habricatorProjectProfileEditController.php | 7 ++----- .../project/query/PhabricatorProjectQuery.php | 21 +++++++++++++++++++ .../project/storage/PhabricatorProject.php | 13 +++++++----- ...torTypeaheadCommonDatasourceController.php | 3 ++- 6 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/applications/project/controller/PhabricatorProjectMembersEditController.php b/src/applications/project/controller/PhabricatorProjectMembersEditController.php index 98067f435c..e4f30dc345 100644 --- a/src/applications/project/controller/PhabricatorProjectMembersEditController.php +++ b/src/applications/project/controller/PhabricatorProjectMembersEditController.php @@ -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(); diff --git a/src/applications/project/controller/PhabricatorProjectProfileController.php b/src/applications/project/controller/PhabricatorProjectProfileController.php index a1e083eff5..953cbb5c11 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileController.php @@ -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(); diff --git a/src/applications/project/controller/PhabricatorProjectProfileEditController.php b/src/applications/project/controller/PhabricatorProjectProfileEditController.php index 2498231ddf..608438ce96 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileEditController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileEditController.php @@ -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(); diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index 820f159d93..0f4c6440e2 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -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; diff --git a/src/applications/project/storage/PhabricatorProject.php b/src/applications/project/storage/PhabricatorProject.php index 78cebb50cf..4d3ec45b6d 100644 --- a/src/applications/project/storage/PhabricatorProject.php +++ b/src/applications/project/storage/PhabricatorProject.php @@ -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) { diff --git a/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php b/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php index fb0c5a66d2..74a4f35563 100644 --- a/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php +++ b/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php @@ -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()); }