2011-02-20 18:41:23 -08:00
|
|
|
<?php
|
|
|
|
|
2012-03-09 15:46:25 -08:00
|
|
|
final class PhabricatorProjectProfileController
|
2011-02-20 18:41:23 -08:00
|
|
|
extends PhabricatorProjectController {
|
|
|
|
|
|
|
|
private $id;
|
2011-06-18 05:13:56 -03:00
|
|
|
private $page;
|
2013-02-13 09:22:14 -08:00
|
|
|
private $project;
|
2011-02-20 18:41:23 -08:00
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
2011-06-18 05:13:56 -03:00
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
$this->page = idx($data, 'page');
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
2011-06-18 05:13:56 -03:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2012-08-15 10:44:58 -07:00
|
|
|
$query = id(new PhabricatorProjectQuery())
|
|
|
|
->setViewer($user)
|
2013-04-15 13:07:54 -07:00
|
|
|
->withIDs(array($this->id))
|
|
|
|
->needMembers(true);
|
2012-08-15 10:44:58 -07:00
|
|
|
|
|
|
|
$project = $query->executeOne();
|
2013-02-13 09:22:14 -08:00
|
|
|
$this->project = $project;
|
2011-02-20 18:41:23 -08:00
|
|
|
if (!$project) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2012-08-15 10:44:58 -07:00
|
|
|
|
Improve performance of project list view
Summary:
D477 added functionality to the project list view but had a couple of
performance issues that I missed in review, because it took the query count for
the page from around 3 to as many as 300, including up to 100 heavyweight search
index queries.
This fixes the two simple N+1 query problems. This general pattern of data
access often occurs:
COUNTEREXAMPLE
$cats = load_cats();
foreach ($cats as $cat) {
$cats_hats = load_hats_for_cat($cat);
// ...
}
But this issues "N+1" queries, i.e. if you load 100 cats you issue 101 queries.
It is faster to group the queries instead:
$cats = load_cats();
$hats = load_all_hats_for_these_cats($cats);
foreach ($cats as $cat) {
$cats_hats = $hats[$cat->getID()];
}
MySQL can execute one query which returns all the results much faster than 100
queries which return one result, especially if the database is not local (i.e.,
over the network).
However, this doesn't save a ton of time. The bigger issue is that I didn't have
the right keys on the relationship tables in the search engine. This adds them,
and reduces the search engine lookup cost from 25-80ms (for
secure.phabricator.com) down to 1-3ms.
I still probably want to get this out of the loop at some point but it's okay
for now and the page loads in a few ms rather than taking more than a second.
Test Plan:
Used "services" tab, "xhprof" and "EXPLAIN" to analyze page performance. I
measured these changes:
- Query count: 1 + (3 * N projects) -> 3 + (N projects) (e.g., 301 -> 103)
- Total time spent querying, ignoring search indexes: 40ms (local.aprhont.com)
-> 20ms (local.aphront.com)
- Cost for search index query: 25-80ms (secure.phabricator.com) -> 1-3ms
Reviewed By: cadamo
Reviewers: cadamo, aran, jungejason, tuomaspelkonen
CC: aran, cadamo, epriestley
Differential Revision: 485
2011-06-20 16:32:44 -07:00
|
|
|
$profile = $project->loadProfile();
|
2011-02-20 18:41:23 -08:00
|
|
|
if (!$profile) {
|
|
|
|
$profile = new PhabricatorProjectProfile();
|
|
|
|
}
|
|
|
|
|
2012-06-26 08:14:15 -07:00
|
|
|
$picture = $profile->loadProfileImageURI();
|
2011-06-18 05:13:56 -03:00
|
|
|
|
2011-12-16 20:01:38 -08:00
|
|
|
require_celerity_resource('phabricator-profile-css');
|
|
|
|
|
2013-04-15 13:07:54 -07:00
|
|
|
$tasks = $this->renderTasksPage($project, $profile);
|
|
|
|
|
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(
|
|
|
|
array(
|
|
|
|
$project->getPHID(),
|
|
|
|
));
|
|
|
|
$query->setLimit(50);
|
|
|
|
$query->setViewer($this->getRequest()->getUser());
|
|
|
|
$stories = $query->execute();
|
|
|
|
$feed = $this->renderStories($stories);
|
|
|
|
$people = $this->renderPeoplePage($project, $profile);
|
|
|
|
|
|
|
|
$content = id(new AphrontMultiColumnView())
|
2013-07-22 09:01:22 -07:00
|
|
|
->addColumn($people)
|
2013-04-15 13:07:54 -07:00
|
|
|
->addColumn($feed)
|
|
|
|
->setFluidLayout(true);
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-04-15 13:07:54 -07:00
|
|
|
$content = hsprintf(
|
|
|
|
'<div class="phabricator-project-layout">%s%s</div>',
|
|
|
|
$tasks,
|
|
|
|
$content);
|
2011-12-16 20:01:38 -08:00
|
|
|
|
2013-07-09 16:23:22 -07:00
|
|
|
$header = id(new PhabricatorHeaderView())
|
|
|
|
->setHeader($project->getName())
|
|
|
|
->setSubheader(phutil_utf8_shorten($profile->getBlurb(), 1024))
|
|
|
|
->setImage($picture);
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
$actions = $this->buildActionListView($project);
|
|
|
|
$properties = $this->buildPropertyListView($project);
|
2013-07-09 16:23:22 -07:00
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($project->getName()));
|
2011-02-20 18:41:23 -08:00
|
|
|
|
2013-02-13 09:22:14 -08:00
|
|
|
return $this->buildApplicationPage(
|
2011-02-20 18:41:23 -08:00
|
|
|
array(
|
2013-07-22 09:01:22 -07:00
|
|
|
$crumbs,
|
|
|
|
$header,
|
|
|
|
$actions,
|
|
|
|
$properties,
|
|
|
|
$content,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $project->getName(),
|
2013-04-15 13:07:54 -07:00
|
|
|
'device' => true,
|
2011-12-16 20:01:38 -08:00
|
|
|
));
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|
|
|
|
|
2011-12-16 20:01:38 -08:00
|
|
|
private function renderPeoplePage(
|
|
|
|
PhabricatorProject $project,
|
|
|
|
PhabricatorProjectProfile $profile) {
|
|
|
|
|
2012-08-15 10:44:58 -07:00
|
|
|
$member_phids = $project->getMemberPHIDs();
|
2012-09-04 19:02:56 -07:00
|
|
|
$handles = $this->loadViewerHandles($member_phids);
|
2011-12-16 20:01:38 -08:00
|
|
|
|
|
|
|
$affiliated = array();
|
2012-08-07 11:55:00 -07:00
|
|
|
foreach ($handles as $phids => $handle) {
|
2013-02-13 14:50:15 -08:00
|
|
|
$affiliated[] = phutil_tag('li', array(), $handle->renderLink());
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($affiliated) {
|
2013-02-13 14:50:15 -08:00
|
|
|
$affiliated = phutil_tag('ul', array(), $affiliated);
|
2011-12-16 20:01:38 -08:00
|
|
|
} else {
|
2013-02-13 14:50:15 -08:00
|
|
|
$affiliated = hsprintf('<p><em>%s</em></p>', pht(
|
|
|
|
'No one is affiliated with this project.'));
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
return hsprintf(
|
2013-04-15 13:07:54 -07:00
|
|
|
'<div class="phabricator-profile-info-group profile-wrap-responsive">'.
|
2013-02-13 14:50:15 -08:00
|
|
|
'<h1 class="phabricator-profile-info-header">%s</h1>'.
|
|
|
|
'<div class="phabricator-profile-info-pane">%s</div>'.
|
|
|
|
'</div>',
|
|
|
|
pht('People'),
|
|
|
|
$affiliated);
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderFeedPage(
|
|
|
|
PhabricatorProject $project,
|
|
|
|
PhabricatorProjectProfile $profile) {
|
|
|
|
|
|
|
|
$query = new PhabricatorFeedQuery();
|
|
|
|
$query->setFilterPHIDs(array($project->getPHID()));
|
2012-07-02 15:41:19 -07:00
|
|
|
$query->setViewer($this->getRequest()->getUser());
|
2012-07-03 06:25:03 -07:00
|
|
|
$query->setLimit(100);
|
2011-12-16 20:01:38 -08:00
|
|
|
$stories = $query->execute();
|
|
|
|
|
|
|
|
if (!$stories) {
|
2013-02-13 09:22:14 -08:00
|
|
|
return pht('There are no stories about this project.');
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
2011-12-22 08:22:07 -08:00
|
|
|
return $this->renderStories($stories);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderStories(array $stories) {
|
2012-04-03 12:10:45 -07:00
|
|
|
assert_instances_of($stories, 'PhabricatorFeedStory');
|
2011-12-22 08:22:07 -08:00
|
|
|
|
2011-12-16 20:01:38 -08:00
|
|
|
$builder = new PhabricatorFeedBuilder($stories);
|
|
|
|
$builder->setUser($this->getRequest()->getUser());
|
2013-08-14 13:20:25 -07:00
|
|
|
$builder->setShowHovercards(true);
|
2011-12-16 20:01:38 -08:00
|
|
|
$view = $builder->buildView();
|
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
return hsprintf(
|
2013-04-15 13:07:54 -07:00
|
|
|
'<div class="profile-feed profile-wrap-responsive">'.
|
|
|
|
'%s'.
|
2013-02-13 14:50:15 -08:00
|
|
|
'</div>',
|
|
|
|
$view->render());
|
2011-12-16 20:01:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function renderTasksPage(
|
|
|
|
PhabricatorProject $project,
|
|
|
|
PhabricatorProjectProfile $profile) {
|
2011-07-07 14:01:55 -07:00
|
|
|
|
2013-03-23 14:38:01 -07:00
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
2011-07-07 14:01:55 -07:00
|
|
|
$query = id(new ManiphestTaskQuery())
|
2013-09-10 07:44:22 -07:00
|
|
|
->setViewer($user)
|
2012-10-04 15:31:04 -07:00
|
|
|
->withAnyProjects(array($project->getPHID()))
|
2011-07-07 14:01:55 -07:00
|
|
|
->withStatus(ManiphestTaskQuery::STATUS_OPEN)
|
|
|
|
->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)
|
|
|
|
->setLimit(10)
|
|
|
|
->setCalculateRows(true);
|
|
|
|
$tasks = $query->execute();
|
|
|
|
$count = $query->getRowCount();
|
|
|
|
|
2011-07-07 16:06:27 -07:00
|
|
|
$phids = mpull($tasks, 'getOwnerPHID');
|
2013-03-23 14:38:01 -07:00
|
|
|
$phids = array_merge(
|
|
|
|
$phids,
|
|
|
|
array_mergev(mpull($tasks, 'getProjectPHIDs')));
|
2011-07-07 16:06:27 -07:00
|
|
|
$phids = array_filter($phids);
|
2012-09-04 19:02:56 -07:00
|
|
|
$handles = $this->loadViewerHandles($phids);
|
2011-07-07 16:06:27 -07:00
|
|
|
|
2013-03-23 14:38:01 -07:00
|
|
|
$task_list = new ManiphestTaskListView();
|
|
|
|
$task_list->setUser($user);
|
|
|
|
$task_list->setTasks($tasks);
|
|
|
|
$task_list->setHandles($handles);
|
2011-07-07 14:01:55 -07:00
|
|
|
|
|
|
|
$open = number_format($count);
|
|
|
|
|
2013-01-17 18:57:09 -08:00
|
|
|
$more_link = phutil_tag(
|
2011-07-07 14:01:55 -07:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/maniphest/view/all/?projects='.$project->getPHID(),
|
|
|
|
),
|
2013-02-13 09:22:14 -08:00
|
|
|
pht("View All Open Tasks \xC2\xBB"));
|
2011-07-07 14:01:55 -07:00
|
|
|
|
2013-02-13 14:50:15 -08:00
|
|
|
$content = hsprintf(
|
2013-04-15 13:07:54 -07:00
|
|
|
'<div class="phabricator-profile-info-group profile-wrap-responsive">
|
2013-02-13 14:50:15 -08:00
|
|
|
<h1 class="phabricator-profile-info-header">%s</h1>'.
|
2011-07-07 14:01:55 -07:00
|
|
|
'<div class="phabricator-profile-info-pane">'.
|
2013-02-13 14:50:15 -08:00
|
|
|
'%s'.
|
|
|
|
'<div class="phabricator-profile-info-pane-more-link">%s</div>'.
|
2011-07-07 14:01:55 -07:00
|
|
|
'</div>
|
2013-02-13 14:50:15 -08:00
|
|
|
</div>',
|
|
|
|
pht('Open Tasks (%s)', $open),
|
2013-03-23 14:38:01 -07:00
|
|
|
$task_list,
|
2013-02-13 14:50:15 -08:00
|
|
|
$more_link);
|
2011-06-18 05:13:56 -03:00
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
2011-07-19 15:50:15 -03:00
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
private function buildActionListView(PhabricatorProject $project) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$id = $project->getID();
|
|
|
|
|
|
|
|
$view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($project)
|
|
|
|
->setObjectURI($request->getRequestURI());
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$project,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Project'))
|
|
|
|
->setIcon('edit')
|
|
|
|
->setHref($this->getApplicationURI("edit/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Edit Members'))
|
|
|
|
->setIcon('edit')
|
|
|
|
->setHref($this->getApplicationURI("members/{$id}/"))
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setWorkflow(!$can_edit));
|
|
|
|
|
|
|
|
|
|
|
|
$action = null;
|
|
|
|
if (!$project->isUserMember($viewer->getPHID())) {
|
|
|
|
$can_join = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$project,
|
|
|
|
PhabricatorPolicyCapability::CAN_JOIN);
|
|
|
|
|
|
|
|
$action = id(new PhabricatorActionView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setRenderAsForm(true)
|
|
|
|
->setHref('/project/update/'.$project->getID().'/join/')
|
|
|
|
->setIcon('new')
|
|
|
|
->setDisabled(!$can_join)
|
|
|
|
->setName(pht('Join Project'));
|
|
|
|
} else {
|
|
|
|
$action = id(new PhabricatorActionView())
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setHref('/project/update/'.$project->getID().'/leave/')
|
|
|
|
->setIcon('delete')
|
|
|
|
->setName(pht('Leave Project...'));
|
|
|
|
}
|
|
|
|
$view->addAction($action);
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyListView(PhabricatorProject $project) {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$view = id(new PhabricatorPropertyListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($project);
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Created'),
|
|
|
|
phabricator_datetime($project->getDateCreated(), $viewer));
|
|
|
|
|
|
|
|
return $view;
|
2013-04-15 13:07:54 -07:00
|
|
|
}
|
|
|
|
|
2013-07-22 09:01:22 -07:00
|
|
|
|
2011-02-20 18:41:23 -08:00
|
|
|
}
|