diff --git a/src/applications/diffusion/controller/DiffusionRepositoryController.php b/src/applications/diffusion/controller/DiffusionRepositoryController.php index 8b9bcb7b29..5d65270c7c 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryController.php @@ -223,7 +223,12 @@ final class DiffusionRepositoryController extends DiffusionController { if (!$repository->isTracked()) { $header->setStatus('fa-ban', 'dark', pht('Inactive')); } else if ($repository->isImporting()) { - $header->setStatus('fa-clock-o', 'indigo', pht('Importing...')); + $ratio = $repository->loadImportProgress(); + $percentage = sprintf('%.2f%%', 100 * $ratio); + $header->setStatus( + 'fa-clock-o', + 'indigo', + pht('Importing (%s)...', $percentage)); } else { $header->setStatus('fa-check', 'bluegrey', pht('Active')); } diff --git a/src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php b/src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php index 1e19d45e7c..bbf7152bf3 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php @@ -1137,45 +1137,8 @@ final class DiffusionRepositoryEditMainController } if ($repository->isImporting()) { - $progress = queryfx_all( - $repository->establishConnection('r'), - 'SELECT importStatus, count(*) N FROM %T WHERE repositoryID = %d - GROUP BY importStatus', - id(new PhabricatorRepositoryCommit())->getTableName(), - $repository->getID()); - - $done = 0; - $total = 0; - foreach ($progress as $row) { - $total += $row['N'] * 4; - $status = $row['importStatus']; - if ($status & PhabricatorRepositoryCommit::IMPORTED_MESSAGE) { - $done += $row['N']; - } - if ($status & PhabricatorRepositoryCommit::IMPORTED_CHANGE) { - $done += $row['N']; - } - if ($status & PhabricatorRepositoryCommit::IMPORTED_OWNERS) { - $done += $row['N']; - } - if ($status & PhabricatorRepositoryCommit::IMPORTED_HERALD) { - $done += $row['N']; - } - } - - if ($total) { - $percentage = 100 * ($done / $total); - } else { - $percentage = 0; - } - - // Cap this at "99.99%", because it's confusing to users when the actual - // fraction is "99.996%" and it rounds up to "100.00%". - if ($percentage > 99.99) { - $percentage = 99.99; - } - - $percentage = sprintf('%.2f%%', $percentage); + $ratio = $repository->loadImportProgress(); + $percentage = sprintf('%.2f%%', 100 * $ratio); $view->addItem( id(new PHUIStatusItemView()) diff --git a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php index 98175f88d7..ad3b61c8df 100644 --- a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php +++ b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php @@ -205,7 +205,7 @@ final class PhabricatorRepositorySearchEngine $item->setDisabled(true); $item->addIcon('disable-grey', pht('Inactive')); } else if ($repository->isImporting()) { - $item->addIcon('fa-clock-o violet', pht('Importing...')); + $item->addIcon('fa-clock-o indigo', pht('Importing...')); } $list->addItem($item); diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 97b9684d0b..c9455d38f8 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -867,6 +867,47 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO return (bool)$this->getDetail('importing', false); } + public function loadImportProgress() { + $progress = queryfx_all( + $this->establishConnection('r'), + 'SELECT importStatus, count(*) N FROM %T WHERE repositoryID = %d + GROUP BY importStatus', + id(new PhabricatorRepositoryCommit())->getTableName(), + $this->getID()); + + $done = 0; + $total = 0; + foreach ($progress as $row) { + $total += $row['N'] * 4; + $status = $row['importStatus']; + if ($status & PhabricatorRepositoryCommit::IMPORTED_MESSAGE) { + $done += $row['N']; + } + if ($status & PhabricatorRepositoryCommit::IMPORTED_CHANGE) { + $done += $row['N']; + } + if ($status & PhabricatorRepositoryCommit::IMPORTED_OWNERS) { + $done += $row['N']; + } + if ($status & PhabricatorRepositoryCommit::IMPORTED_HERALD) { + $done += $row['N']; + } + } + + if ($total) { + $ratio = ($done / $total); + } else { + $ratio = 0; + } + + // Cap this at "99.99%", because it's confusing to users when the actual + // fraction is "99.996%" and it rounds up to "100.00%". + if ($ratio > 0.9999) { + $ratio = 0.9999; + } + + return $ratio; + } /** * Should this repository publish feed, notifications, audits, and email?