1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Home - limit "status" queries to 100 and show 99+ if we hit that

Summary: Fixes T6595. This diff has two issues as is... 1) the differential data fetching is pretty cheesey, but it looks like we can't just issue three separate databases to get the right data? 2) the translations break, since I am turning this into a string (and not an int) so the whole pluralization bit fails. I think 1 is okay as is and 2 needs to be fixed though I am not sure how to best do that...

Test Plan: loaded home page and it looked nice...!

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T6595

Differential Revision: https://secure.phabricator.com/D10979
This commit is contained in:
Bob Trahan 2014-12-12 12:02:25 -08:00
parent 905fc217b8
commit 2b99b4add8
11 changed files with 126 additions and 38 deletions

View file

@ -54,28 +54,38 @@ final class PhabricatorAuditApplication extends PhabricatorApplication {
$query = id(new DiffusionCommitQuery())
->setViewer($user)
->withAuthorPHIDs(array($user->getPHID()))
->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_CONCERN);
->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_CONCERN)
->setLimit(self::MAX_STATUS_ITEMS);
$commits = $query->execute();
$count = count($commits);
$count_str = self::formatStatusCount(
$count,
'%s Problem Commits',
'%d Problem Commit(s)');
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%d Problem Commit(s)', $count))
->setText($count_str)
->setCount($count);
$query = id(new DiffusionCommitQuery())
->setViewer($user)
->withAuditorPHIDs($phids)
->withAuditStatus(DiffusionCommitQuery::AUDIT_STATUS_OPEN)
->withAuditAwaitingUser($user);
->withAuditAwaitingUser($user)
->setLimit(self::MAX_STATUS_ITEMS);
$commits = $query->execute();
$count = count($commits);
$count_str = self::formatStatusCount(
$count,
'%s Commits Awaiting Audit',
'%d Commit(s) Awaiting Audit');
$type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%d Commit(s) Awaiting Audit', $count))
->setText($count_str)
->setCount($count);
return $status;

View file

@ -9,6 +9,8 @@
*/
abstract class PhabricatorApplication implements PhabricatorPolicyInterface {
const MAX_STATUS_ITEMS = 100;
const GROUP_CORE = 'core';
const GROUP_UTILITIES = 'util';
const GROUP_ADMIN = 'admin';
@ -231,6 +233,22 @@ abstract class PhabricatorApplication implements PhabricatorPolicyInterface {
return array();
}
/**
* @return string
* @task ui
*/
public static function formatStatusCount(
$count,
$limit_string = '%s',
$base_string = '%d') {
if ($count == self::MAX_STATUS_ITEMS) {
$count_str = pht($limit_string, ($count - 1).'+');
} else {
$count_str = pht($base_string, $count);
}
return $count_str;
}
/**
* You can provide an optional piece of flavor text for the application. This

View file

@ -100,35 +100,60 @@ EOTEXT
->withResponsibleUsers(array($user->getPHID()))
->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
->needRelationships(true)
->setLimit(self::MAX_STATUS_ITEMS)
->execute();
list($blocking, $active, $waiting) =
DifferentialRevisionQuery::splitResponsible(
$revisions,
array($user->getPHID()));
$status = array();
if (count($revisions) == self::MAX_STATUS_ITEMS) {
$all_count = count($revisions);
$all_count_str = self::formatStatusCount(
$all_count,
'%s Active Reviews',
'%d Active Review(s)');
$type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText($all_count_str)
->setCount($all_count);
} else {
list($blocking, $active, $waiting) =
DifferentialRevisionQuery::splitResponsible(
$revisions,
array($user->getPHID()));
$blocking = count($blocking);
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%d Review(s) Blocking Others', $blocking))
->setCount($blocking);
$blocking = count($blocking);
$blocking_str = self::formatStatusCount(
$blocking,
'%s Reviews Blocking Others',
'%d Review(s) Blocking Others');
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText($blocking_str)
->setCount($blocking);
$active = count($active);
$type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%d Review(s) Need Attention', $active))
->setCount($active);
$active = count($active);
$active_str = self::formatStatusCount(
$active,
'%s Reviews Need Attention',
'%d Review(s) Need Attention');
$type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText($active_str)
->setCount($active);
$waiting = count($waiting);
$type = PhabricatorApplicationStatusView::TYPE_INFO;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%d Review(s) Waiting on Others', $waiting))
->setCount($waiting);
$waiting = count($waiting);
$waiting_str = self::formatStatusCount(
$waiting,
'%s Reviews Waiting on Others',
'%d Review(s) Waiting on Others');
$type = PhabricatorApplicationStatusView::TYPE_INFO;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText($waiting_str)
->setCount($waiting);
}
return $status;
}

View file

@ -38,13 +38,18 @@ final class PhabricatorFlagsApplication extends PhabricatorApplication {
$flags = id(new PhabricatorFlagQuery())
->setViewer($user)
->withOwnerPHIDs(array($user->getPHID()))
->setLimit(self::MAX_STATUS_ITEMS)
->execute();
$count = count($flags);
$count_str = self::formatStatusCount(
$count,
'%s Flagged Objects',
'%d Flagged Object(s)');
$type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%d Flagged Object(s)', $count))
->setText($count_str)
->setCount($count);
return $status;

View file

@ -80,13 +80,18 @@ final class PhabricatorManiphestApplication extends PhabricatorApplication {
$query = id(new ManiphestTaskQuery())
->setViewer($user)
->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())
->withOwners(array($user->getPHID()));
->withOwners(array($user->getPHID()))
->setLimit(self::MAX_STATUS_ITEMS);
$count = count($query->execute());
$count_str = self::formatStatusCount(
$count,
'%s Assigned Tasks',
'%d Assigned Task(s)');
$type = PhabricatorApplicationStatusView::TYPE_WARNING;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%s Assigned Task(s)', new PhutilNumber($count)))
->setText($count_str)
->setCount($count);
return $status;

View file

@ -73,7 +73,7 @@ final class PhabricatorApplicationLaunchView extends AphrontTagView {
array(
'class' => 'phabricator-application-attention-count',
),
$count);
PhabricatorApplication::formatStatusCount($count));
}
@ -83,7 +83,7 @@ final class PhabricatorApplicationLaunchView extends AphrontTagView {
array(
'class' => 'phabricator-application-warning-count',
),
$counts[$warning]);
PhabricatorApplication::formatStatusCount($counts[$warning]));
}
if (nonempty($count1) && nonempty($count2)) {
$numbers = array($count1, ' / ', $count2);

View file

@ -91,6 +91,7 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
->setViewer($user)
->withIsApproved(false)
->withIsDisabled(false)
->setLimit(self::MAX_STATUS_ITEMS)
->execute();
if (!$need_approval) {
@ -100,10 +101,14 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
$status = array();
$count = count($need_approval);
$count_str = self::formatStatusCount(
$count,
'%s Users Need Approval',
'%d User(s) Need Approval');
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%d User(s) Need Approval', $count))
->setText($count_str)
->setCount($count);
return $status;

View file

@ -52,11 +52,17 @@ final class PhabricatorPhrequentApplication extends PhabricatorApplication {
// Show number of objects that are currently
// being tracked for a user.
$count = PhrequentUserTimeQuery::getUserTotalObjectsTracked($user);
$count = PhrequentUserTimeQuery::getUserTotalObjectsTracked(
$user,
self::MAX_STATUS_ITEMS);
$count_str = self::formatStatusCount(
$count,
'%s Objects Tracked',
'%d Object(s) Tracked');
$type = PhabricatorApplicationStatusView::TYPE_NEEDS_ATTENTION;
$status[] = id(new PhabricatorApplicationStatusView())
->setType($type)
->setText(pht('%d Object(s) Tracked', $count))
->setText($count_str)
->setCount($count);
return $status;

View file

@ -255,7 +255,8 @@ final class PhrequentUserTimeQuery
}
public static function getUserTotalObjectsTracked(
PhabricatorUser $user) {
PhabricatorUser $user,
$limit = PHP_INT_MAX) {
$usertime_dao = new PhrequentUserTime();
$conn = $usertime_dao->establishConnection('r');
@ -264,9 +265,11 @@ final class PhrequentUserTimeQuery
$conn,
'SELECT COUNT(usertime.id) N FROM %T usertime '.
'WHERE usertime.userPHID = %s '.
'AND usertime.dateEnded IS NULL',
'AND usertime.dateEnded IS NULL '.
'LIMIT %d',
$usertime_dao->getTableName(),
$user->getPHID());
$user->getPHID(),
$limit);
return $count['N'];
}

View file

@ -30,6 +30,7 @@ final class PhabricatorPonderApplication extends PhabricatorApplication {
public function loadStatus(PhabricatorUser $user) {
// replace with "x new unanswered questions" or some such
// make sure to use self::formatStatusCount and friends...!
$status = array();
return $status;

View file

@ -172,11 +172,21 @@ abstract class PhabricatorBaseEnglishTranslation
'%d Reviews Waiting on Others',
),
'%d Active Review(s)' => array(
'%d Active Review',
'%d Active Reviews',
),
'%d Flagged Object(s)' => array(
'%d Flagged Object',
'%d Flagged Objects',
),
'%d Object(s) Tracked' => array(
'%d Object Tracked',
'%d Objects Tracked',
),
'%d Unbreak Now Task(s)!' => array(
'%d Unbreak Now Task!',
'%d Unbreak Now Tasks!',