Page MenuHomePhabricator

D15005.id36255.diff
No OneTemporary

D15005.id36255.diff

diff --git a/resources/sql/autopatches/20160112.repo.01.uri.sql b/resources/sql/autopatches/20160112.repo.01.uri.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160112.repo.01.uri.sql
@@ -0,0 +1,7 @@
+CREATE TABLE {$NAMESPACE}_repository.repository_uriindex (
+ id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ repositoryPHID VARBINARY(64) NOT NULL,
+ repositoryURI LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT},
+ KEY `key_repository` (repositoryPHID),
+ KEY `key_uri` (repositoryURI(128))
+) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
diff --git a/resources/sql/autopatches/20160112.repo.02.uri.index.php b/resources/sql/autopatches/20160112.repo.02.uri.index.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160112.repo.02.uri.index.php
@@ -0,0 +1,7 @@
+<?php
+
+$table = new PhabricatorRepository();
+
+foreach (new LiskMigrationIterator($table) as $repo) {
+ $repo->updateURIIndex();
+}
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -734,6 +734,7 @@
'DiffusionRepositorySymbolsController' => 'applications/diffusion/controller/DiffusionRepositorySymbolsController.php',
'DiffusionRepositoryTag' => 'applications/diffusion/data/DiffusionRepositoryTag.php',
'DiffusionRepositoryTestAutomationController' => 'applications/diffusion/controller/DiffusionRepositoryTestAutomationController.php',
+ 'DiffusionRepositoryURIsIndexEngineExtension' => 'applications/diffusion/engineextension/DiffusionRepositoryURIsIndexEngineExtension.php',
'DiffusionRequest' => 'applications/diffusion/request/DiffusionRequest.php',
'DiffusionResolveRefsConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionResolveRefsConduitAPIMethod.php',
'DiffusionResolveUserQuery' => 'applications/diffusion/query/DiffusionResolveUserQuery.php',
@@ -3009,6 +3010,7 @@
'PhabricatorRepositoryTransaction' => 'applications/repository/storage/PhabricatorRepositoryTransaction.php',
'PhabricatorRepositoryTransactionQuery' => 'applications/repository/query/PhabricatorRepositoryTransactionQuery.php',
'PhabricatorRepositoryType' => 'applications/repository/constants/PhabricatorRepositoryType.php',
+ 'PhabricatorRepositoryURIIndex' => 'applications/repository/storage/PhabricatorRepositoryURIIndex.php',
'PhabricatorRepositoryURINormalizer' => 'applications/repository/data/PhabricatorRepositoryURINormalizer.php',
'PhabricatorRepositoryURINormalizerTestCase' => 'applications/repository/data/__tests__/PhabricatorRepositoryURINormalizerTestCase.php',
'PhabricatorRepositoryURITestCase' => 'applications/repository/storage/__tests__/PhabricatorRepositoryURITestCase.php',
@@ -4707,6 +4709,7 @@
'DiffusionRepositorySymbolsController' => 'DiffusionRepositoryEditController',
'DiffusionRepositoryTag' => 'Phobject',
'DiffusionRepositoryTestAutomationController' => 'DiffusionRepositoryEditController',
+ 'DiffusionRepositoryURIsIndexEngineExtension' => 'PhabricatorIndexEngineExtension',
'DiffusionRequest' => 'Phobject',
'DiffusionResolveRefsConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
'DiffusionResolveUserQuery' => 'Phobject',
@@ -7415,6 +7418,7 @@
'PhabricatorRepositoryTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorRepositoryTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorRepositoryType' => 'Phobject',
+ 'PhabricatorRepositoryURIIndex' => 'PhabricatorRepositoryDAO',
'PhabricatorRepositoryURINormalizer' => 'Phobject',
'PhabricatorRepositoryURINormalizerTestCase' => 'PhabricatorTestCase',
'PhabricatorRepositoryURITestCase' => 'PhabricatorTestCase',
diff --git a/src/applications/diffusion/DiffusionLintSaveRunner.php b/src/applications/diffusion/DiffusionLintSaveRunner.php
--- a/src/applications/diffusion/DiffusionLintSaveRunner.php
+++ b/src/applications/diffusion/DiffusionLintSaveRunner.php
@@ -71,7 +71,7 @@
} else if ($uuid) {
$repository_query->withUUIDs(array($uuid));
} else if ($remote_uri) {
- $repository_query->withRemoteURIs(array($remote_uri));
+ $repository_query->withURIs(array($remote_uri));
}
$repository = $repository_query->executeOne();
diff --git a/src/applications/diffusion/engineextension/DiffusionRepositoryURIsIndexEngineExtension.php b/src/applications/diffusion/engineextension/DiffusionRepositoryURIsIndexEngineExtension.php
new file mode 100644
--- /dev/null
+++ b/src/applications/diffusion/engineextension/DiffusionRepositoryURIsIndexEngineExtension.php
@@ -0,0 +1,22 @@
+<?php
+
+final class DiffusionRepositoryURIsIndexEngineExtension
+ extends PhabricatorIndexEngineExtension {
+
+ const EXTENSIONKEY = 'diffusion.repositories.uri';
+
+ public function getExtensionName() {
+ return pht('Repository URIs');
+ }
+
+ public function shouldIndexObject($object) {
+ return ($object instanceof PhabricatorRepository);
+ }
+
+ public function indexObject(
+ PhabricatorIndexEngine $engine,
+ $object) {
+ $object->updateURIIndex();
+ }
+
+}
diff --git a/src/applications/repository/conduit/RepositoryQueryConduitAPIMethod.php b/src/applications/repository/conduit/RepositoryQueryConduitAPIMethod.php
--- a/src/applications/repository/conduit/RepositoryQueryConduitAPIMethod.php
+++ b/src/applications/repository/conduit/RepositoryQueryConduitAPIMethod.php
@@ -63,7 +63,7 @@
$remote_uris = $request->getValue('remoteURIs', array());
if ($remote_uris) {
- $query->withRemoteURIs($remote_uris);
+ $query->withURIs($remote_uris);
}
$uuids = $request->getValue('uuids', array());
diff --git a/src/applications/repository/editor/PhabricatorRepositoryEditor.php b/src/applications/repository/editor/PhabricatorRepositoryEditor.php
--- a/src/applications/repository/editor/PhabricatorRepositoryEditor.php
+++ b/src/applications/repository/editor/PhabricatorRepositoryEditor.php
@@ -518,4 +518,8 @@
throw new PhabricatorApplicationTransactionValidationException($errors);
}
+ protected function supportsSearch() {
+ return true;
+ }
+
}
diff --git a/src/applications/repository/query/PhabricatorRepositoryQuery.php b/src/applications/repository/query/PhabricatorRepositoryQuery.php
--- a/src/applications/repository/query/PhabricatorRepositoryQuery.php
+++ b/src/applications/repository/query/PhabricatorRepositoryQuery.php
@@ -9,7 +9,7 @@
private $types;
private $uuids;
private $nameContains;
- private $remoteURIs;
+ private $uris;
private $datasourceQuery;
private $slugs;
@@ -118,8 +118,8 @@
return $this;
}
- public function withRemoteURIs(array $uris) {
- $this->remoteURIs = $uris;
+ public function withURIs(array $uris) {
+ $this->uris = $uris;
return $this;
}
@@ -263,17 +263,6 @@
}
}
- // TODO: Denormalize this, too.
- if ($this->remoteURIs) {
- $try_uris = $this->getNormalizedPaths();
- $try_uris = array_fuse($try_uris);
- foreach ($repositories as $key => $repository) {
- if (!isset($try_uris[$repository->getNormalizedPath()])) {
- unset($repositories[$key]);
- }
- }
- }
-
// Build the identifierMap
if ($this->numericIdentifiers) {
foreach ($this->numericIdentifiers as $id) {
@@ -445,6 +434,8 @@
protected function buildSelectClauseParts(AphrontDatabaseConnection $conn) {
$parts = parent::buildSelectClauseParts($conn);
+ $parts[] = 'r.*';
+
if ($this->shouldJoinSummaryTable()) {
$parts[] = 's.*';
}
@@ -462,9 +453,28 @@
PhabricatorRepository::TABLE_SUMMARY);
}
+ if ($this->shouldJoinURITable()) {
+ $joins[] = qsprintf(
+ $conn,
+ 'LEFT JOIN %T uri ON r.phid = uri.repositoryPHID',
+ id(new PhabricatorRepositoryURIIndex())->getTableName());
+ }
+
return $joins;
}
+ protected function shouldGroupQueryResultRows() {
+ if ($this->shouldJoinURITable()) {
+ return true;
+ }
+
+ return parent::shouldGroupQueryResultRows();
+ }
+
+ private function shouldJoinURITable() {
+ return ($this->uris !== null);
+ }
+
private function shouldJoinSummaryTable() {
if ($this->needCommitCounts) {
return true;
@@ -592,7 +602,7 @@
if (strlen($this->nameContains)) {
$where[] = qsprintf(
$conn,
- 'name LIKE %~',
+ 'r.name LIKE %~',
$this->nameContains);
}
@@ -619,6 +629,16 @@
$this->slugs);
}
+ if ($this->uris !== null) {
+ $try_uris = $this->getNormalizedPaths();
+ $try_uris = array_fuse($try_uris);
+
+ $where[] = qsprintf(
+ $conn,
+ 'uri.repositoryURI IN (%Ls)',
+ $try_uris);
+ }
+
return $where;
}
@@ -635,7 +655,7 @@
// or an `svn+ssh` URI, we could deduce how to normalize it. However, this
// would be more complicated and it's not clear if it matters in practice.
- foreach ($this->remoteURIs as $uri) {
+ foreach ($this->uris as $uri) {
$normalized_uris[] = new PhabricatorRepositoryURINormalizer(
PhabricatorRepositoryURINormalizer::TYPE_GIT,
$uri);
diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php
--- a/src/applications/repository/storage/PhabricatorRepository.php
+++ b/src/applications/repository/storage/PhabricatorRepository.php
@@ -823,30 +823,40 @@
return $uri;
}
- public function getNormalizedPath() {
- $uri = (string)$this->getCloneURIObject();
+ public function updateURIIndex() {
+ $uris = array(
+ (string)$this->getCloneURIObject(),
+ );
+
+ foreach ($uris as $key => $uri) {
+ $uris[$key] = $this->getNormalizedURI($uri)
+ ->getNormalizedPath();
+ }
+
+ PhabricatorRepositoryURIIndex::updateRepositoryURIs(
+ $this->getPHID(),
+ $uris);
+
+ return $this;
+ }
+ private function getNormalizedURI($uri) {
switch ($this->getVersionControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
- $normalized_uri = new PhabricatorRepositoryURINormalizer(
+ return new PhabricatorRepositoryURINormalizer(
PhabricatorRepositoryURINormalizer::TYPE_GIT,
$uri);
- break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
- $normalized_uri = new PhabricatorRepositoryURINormalizer(
+ return new PhabricatorRepositoryURINormalizer(
PhabricatorRepositoryURINormalizer::TYPE_SVN,
$uri);
- break;
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
- $normalized_uri = new PhabricatorRepositoryURINormalizer(
+ return new PhabricatorRepositoryURINormalizer(
PhabricatorRepositoryURINormalizer::TYPE_MERCURIAL,
$uri);
- break;
default:
throw new Exception(pht('Unrecognized version control system.'));
}
-
- return $normalized_uri->getNormalizedPath();
}
public function isTracked() {
@@ -2231,13 +2241,17 @@
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
+ $phid = $this->getPHID();
+
$this->openTransaction();
$this->delete();
+ PhabricatorRepositoryURIIndex::updateRepositoryURIs($phid, array());
+
$books = id(new DivinerBookQuery())
->setViewer($engine->getViewer())
- ->withRepositoryPHIDs(array($this->getPHID()))
+ ->withRepositoryPHIDs(array($phid))
->execute();
foreach ($books as $book) {
$engine->destroyObject($book);
@@ -2245,7 +2259,7 @@
$atoms = id(new DivinerAtomQuery())
->setViewer($engine->getViewer())
- ->withRepositoryPHIDs(array($this->getPHID()))
+ ->withRepositoryPHIDs(array($phid))
->execute();
foreach ($atoms as $atom) {
$engine->destroyObject($atom);
diff --git a/src/applications/repository/storage/PhabricatorRepositoryURIIndex.php b/src/applications/repository/storage/PhabricatorRepositoryURIIndex.php
new file mode 100644
--- /dev/null
+++ b/src/applications/repository/storage/PhabricatorRepositoryURIIndex.php
@@ -0,0 +1,67 @@
+<?php
+
+final class PhabricatorRepositoryURIIndex
+ extends PhabricatorRepositoryDAO {
+
+ protected $repositoryPHID;
+ protected $repositoryURI;
+
+ protected function getConfiguration() {
+ return array(
+ self::CONFIG_TIMESTAMPS => false,
+ self::CONFIG_COLUMN_SCHEMA => array(
+ 'repositoryURI' => 'text',
+ ),
+ self::CONFIG_KEY_SCHEMA => array(
+ 'key_repository' => array(
+ 'columns' => array('repositoryPHID'),
+ ),
+ 'key_uri' => array(
+ 'columns' => array('repositoryURI(128)'),
+ ),
+ ),
+ ) + parent::getConfiguration();
+ }
+
+ public static function updateRepositoryURIs(
+ $repository_phid,
+ array $uris) {
+
+ $table = new self();
+ $conn_w = $table->establishConnection('w');
+
+ $sql = array();
+ foreach ($uris as $key => $uri) {
+ if (!strlen($uri)) {
+ unset($uris[$key]);
+ continue;
+ }
+
+ $sql[] = qsprintf(
+ $conn_w,
+ '(%s, %s)',
+ $repository_phid,
+ $uri);
+ }
+
+ $table->openTransaction();
+
+ queryfx(
+ $conn_w,
+ 'DELETE FROM %T WHERE repositoryPHID = %s',
+ $table->getTableName(),
+ $repository_phid);
+
+ if ($sql) {
+ queryfx(
+ $conn_w,
+ 'INSERT INTO %T (repositoryPHID, repositoryURI) VALUES %Q',
+ $table->getTableName(),
+ implode(', ', $sql));
+ }
+
+ $table->saveTransaction();
+
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 28, 7:45 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7705275
Default Alt Text
D15005.id36255.diff (13 KB)

Event Timeline