Differential D15570 Diff 37575 src/applications/people/controller/PhabricatorPeopleProfileViewController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/controller/PhabricatorPeopleProfileViewController.php
Show First 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | private function buildBadgesView(PhabricatorUser $user) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$class = 'PhabricatorBadgesApplication'; | $class = 'PhabricatorBadgesApplication'; | ||||
if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { | if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { | ||||
return null; | return null; | ||||
} | } | ||||
$badge_phids = $user->getBadgePHIDs(); | $awards = array(); | ||||
if ($badge_phids) { | $badges = array(); | ||||
if ($user->getBadgePHIDs()) { | |||||
$awards = id(new PhabricatorBadgesAwardQuery()) | |||||
->setViewer($viewer) | |||||
->withRecipientPHIDs(array($user->getPHID())) | |||||
->execute(); | |||||
$awards = mpull($awards, null, 'getBadgePHID'); | |||||
$badge_phids = mpull($awards, 'getBadgePHID'); | |||||
$badges = id(new PhabricatorBadgesQuery()) | $badges = id(new PhabricatorBadgesQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs($badge_phids) | ->withPHIDs($badge_phids) | ||||
->withStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE)) | ->withStatuses(array(PhabricatorBadgesBadge::STATUS_ACTIVE)) | ||||
->execute(); | ->execute(); | ||||
epriestley: Specifically, this makes us load more data than we need. | |||||
} else { | $badges = mpull($badges, null, 'getPHID'); | ||||
Not Done Inline ActionsI know this seems like two queries right out of the gate might be aggressive, but my thinking was: if a user has badgePHIDs, then there are definitely awards, and we would still have to make a second query to get badges, even if all those badges were archived. lpriestley: I know this seems like two queries right out of the gate might be aggressive, but my thinking… | |||||
$badges = array(); | |||||
} | } | ||||
if (count($badges)) { | if (count($badges)) { | ||||
$flex = new PHUIBadgeBoxView(); | $flex = new PHUIBadgeBoxView(); | ||||
foreach ($badges as $badge) { | foreach ($badges as $badge) { | ||||
if ($badge) { | |||||
$awarder_info = array(); | |||||
$award = idx($awards, $badge->getPHID(), null); | |||||
$awarder_phid = $award->getAwarderPHID(); | |||||
$awarder_handle = $viewer->renderHandle($awarder_phid); | |||||
Not Done Inline ActionsTurns out, because the card flips on click, you can't actually click the user handle on it. Is there away to make the handle unclickable? lpriestley: Turns out, because the card flips on click, you can't actually click the user handle on it. Is… | |||||
$awarder_info = pht( | |||||
'Awarded by %s', | |||||
$awarder_handle->render()); | |||||
$item = id(new PHUIBadgeView()) | $item = id(new PHUIBadgeView()) | ||||
->setIcon($badge->getIcon()) | ->setIcon($badge->getIcon()) | ||||
->setHeader($badge->getName()) | ->setHeader($badge->getName()) | ||||
->setSubhead($badge->getFlavor()) | ->setSubhead($badge->getFlavor()) | ||||
->setQuality($badge->getQuality()); | ->setQuality($badge->getQuality()) | ||||
->addByLine($awarder_info); | |||||
$flex->addItem($item); | $flex->addItem($item); | ||||
} | } | ||||
} | |||||
} else { | } else { | ||||
$error = id(new PHUIBoxView()) | $error = id(new PHUIBoxView()) | ||||
->addClass('mlb') | ->addClass('mlb') | ||||
->appendChild(pht('User does not have any badges.')); | ->appendChild(pht('User does not have any badges.')); | ||||
$flex = id(new PHUIInfoView()) | $flex = id(new PHUIInfoView()) | ||||
->setSeverity(PHUIInfoView::SEVERITY_NODATA) | ->setSeverity(PHUIInfoView::SEVERITY_NODATA) | ||||
->appendChild($error); | ->appendChild($error); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |
Specifically, this makes us load more data than we need.