From f21972a01f1a67c335812017db1abea05b5be7d9 Mon Sep 17 00:00:00 2001 From: Aviv Eyal Date: Thu, 21 May 2015 08:25:34 -0700 Subject: [PATCH] Only link symbols if there might be any Summary: fixes T8260. Only turn on symbol links if: - The repository has any configuration about symbols, or - There actually are symbols in the repository. Test Plan: Look at revisions and files in various states of configurations and having symbols. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: joshuaspence, Korvin, epriestley Maniphest Tasks: T8260 Differential Revision: https://secure.phabricator.com/D12946 --- .../DifferentialRevisionViewController.php | 27 ++++++++++--------- .../DiffusionBrowseFileController.php | 19 +++++++++++-- .../diffusion/query/DiffusionSymbolQuery.php | 20 ++++++++++++++ 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php index 849ef056aa..cdefdd65d7 100644 --- a/src/applications/differential/controller/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/DifferentialRevisionViewController.php @@ -261,12 +261,11 @@ final class DifferentialRevisionViewController extends DifferentialController { $repository = $revision->getRepository(); if ($repository) { - list($symbol_indexes, $repository_phids) = $this->buildSymbolIndexes( + $symbol_indexes = $this->buildSymbolIndexes( $repository, $visible_changesets); } else { $symbol_indexes = array(); - $repository_phids = null; } $revision_detail->setActions($actions); @@ -306,15 +305,6 @@ final class DifferentialRevisionViewController extends DifferentialController { ), $comment_view); - if ($repository) { - Javelin::initBehavior( - 'repository-crossreference', - array( - 'section' => $wrap_id, - 'repositories' => $repository_phids, - )); - } - $changeset_view = new DifferentialChangesetListView(); $changeset_view->setChangesets($changesets); $changeset_view->setVisibleChangesets($visible_changesets); @@ -758,11 +748,22 @@ final class DifferentialRevisionViewController extends DifferentialController { $langs = $repository->getSymbolLanguages(); $langs = nonempty($langs, array()); + $sources = $repository->getSymbolSources(); + $sources = nonempty($sources, array()); + $symbol_indexes = array(); + if ($langs && $sources) { + $have_symbols = id(new DiffusionSymbolQuery()) + ->existsSymbolsInRepository($repository->getPHID()); + if (!$have_symbols) { + return $symbol_indexes; + } + } + $repository_phids = array_merge( array($repository->getPHID()), - nonempty($repository->getSymbolSources(), array())); + $sources); $indexed_langs = array_fill_keys($langs, true); foreach ($visible_changesets as $key => $changeset) { @@ -775,7 +776,7 @@ final class DifferentialRevisionViewController extends DifferentialController { } } - return array($symbol_indexes, $repository_phids); + return $symbol_indexes; } private function loadOtherRevisions( diff --git a/src/applications/diffusion/controller/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/DiffusionBrowseFileController.php index 731906943c..6fcda177a5 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseFileController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseFileController.php @@ -267,13 +267,28 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController { $id = celerity_generate_unique_node_id(); $repo = $drequest->getRepository(); - $symbol_repos = $repo->getSymbolSources(); + $symbol_repos = nonempty($repo->getSymbolSources(), array()); $symbol_repos[] = $repo; $lang = last(explode('.', $drequest->getPath())); $repo_languages = $repo->getSymbolLanguages(); + $repo_languages = nonempty($repo_languages, array()); $repo_languages = array_fill_keys($repo_languages, true); - if (empty($repo_languages) || isset($repo_languages[$lang])) { + + $needs_symbols = true; + if ($repo_languages && $symbol_repos) { + $have_symbols = id(new DiffusionSymbolQuery()) + ->existsSymbolsInRepository($repo->getPHID()); + if (!$have_symbols) { + $needs_symbols = false; + } + } + + if ($needs_symbols && $repo_languages) { + $needs_symbols = isset($repo_languages[$lang]); + } + + if ($needs_symbols) { Javelin::initBehavior( 'repository-crossreference', array( diff --git a/src/applications/diffusion/query/DiffusionSymbolQuery.php b/src/applications/diffusion/query/DiffusionSymbolQuery.php index 6017c45f6f..0e08b7b32d 100644 --- a/src/applications/diffusion/query/DiffusionSymbolQuery.php +++ b/src/applications/diffusion/query/DiffusionSymbolQuery.php @@ -113,6 +113,26 @@ final class DiffusionSymbolQuery extends PhabricatorOffsetPagedQuery { } +/* -( Specialized Query )-------------------------------------------------- */ + + public function existsSymbolsInRepository($repository_phid) { + $this + ->withRepositoryPHIDs(array($repository_phid)) + ->setLimit(1); + + $symbol = new PhabricatorRepositorySymbol(); + $conn_r = $symbol->establishConnection('r'); + + $data = queryfx_all( + $conn_r, + 'SELECT * FROM %T %Q %Q', + $symbol->getTableName(), + $this->buildWhereClause($conn_r), + $this->buildLimitClause($conn_r)); + + return (!empty($data)); + } + /* -( Executing the Query )------------------------------------------------ */