mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
Provide and populate an object name index for Maniphest
Summary: See discussion in D6955. This provides a table we can JOIN against to (effectively) "ORDER BY project name", populates it intially, and keeps it up to date as projects are edited. Test Plan: - Ran storage upgrade, verified projects populated into the table. - Edited a project, verified its entry updated. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D6957
This commit is contained in:
parent
da50aef7f2
commit
e50eccf109
8 changed files with 96 additions and 0 deletions
9
resources/sql/patches/20130912.maniphest.3.nameindex.sql
Normal file
9
resources/sql/patches/20130912.maniphest.3.nameindex.sql
Normal file
|
@ -0,0 +1,9 @@
|
|||
CREATE TABLE {$NAMESPACE}_maniphest.maniphest_nameindex (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
indexedObjectPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
|
||||
indexedObjectName VARCHAR(128) NOT NULL,
|
||||
|
||||
UNIQUE KEY `key_phid` (indexedObjectPHID),
|
||||
KEY `key_name` (indexedObjectName)
|
||||
|
||||
) ENGINE=InnoDB, COLLATE utf8_general_ci;
|
16
resources/sql/patches/20130912.maniphest.4.fillindex.php
Normal file
16
resources/sql/patches/20130912.maniphest.4.fillindex.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
// Update the "PROJ" search index, to:
|
||||
//
|
||||
// - Populate the index itself, which was added recently.
|
||||
// - Populate the secondary object name index in Maniphest.
|
||||
|
||||
$root = dirname(phutil_get_library_root('phabricator'));
|
||||
|
||||
$command = new PhutilExecPassthru(
|
||||
'php -f %s -- index --type PROJ',
|
||||
$root.'/scripts/search/manage_search.php');
|
||||
$err = $command->execute();
|
||||
if ($err) {
|
||||
throw new Exception("Update failed!");
|
||||
}
|
|
@ -698,6 +698,8 @@ phutil_register_library_map(array(
|
|||
'ManiphestExcelFormat' => 'applications/maniphest/export/ManiphestExcelFormat.php',
|
||||
'ManiphestExportController' => 'applications/maniphest/controller/ManiphestExportController.php',
|
||||
'ManiphestHovercardEventListener' => 'applications/maniphest/event/ManiphestHovercardEventListener.php',
|
||||
'ManiphestNameIndex' => 'applications/maniphest/storage/ManiphestNameIndex.php',
|
||||
'ManiphestNameIndexEventListener' => 'applications/maniphest/event/ManiphestNameIndexEventListener.php',
|
||||
'ManiphestPHIDTypeTask' => 'applications/maniphest/phid/ManiphestPHIDTypeTask.php',
|
||||
'ManiphestPeopleMenuEventListener' => 'applications/maniphest/event/ManiphestPeopleMenuEventListener.php',
|
||||
'ManiphestRemarkupRule' => 'applications/maniphest/remarkup/ManiphestRemarkupRule.php',
|
||||
|
@ -2762,6 +2764,8 @@ phutil_register_library_map(array(
|
|||
'ManiphestExcelDefaultFormat' => 'ManiphestExcelFormat',
|
||||
'ManiphestExportController' => 'ManiphestController',
|
||||
'ManiphestHovercardEventListener' => 'PhutilEventListener',
|
||||
'ManiphestNameIndex' => 'ManiphestDAO',
|
||||
'ManiphestNameIndexEventListener' => 'PhutilEventListener',
|
||||
'ManiphestPHIDTypeTask' => 'PhabricatorPHIDType',
|
||||
'ManiphestPeopleMenuEventListener' => 'PhutilEventListener',
|
||||
'ManiphestRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
||||
|
|
|
@ -34,6 +34,7 @@ final class PhabricatorApplicationManiphest extends PhabricatorApplication {
|
|||
|
||||
public function getEventListeners() {
|
||||
return array(
|
||||
new ManiphestNameIndexEventListener(),
|
||||
new ManiphestPeopleMenuEventListener(),
|
||||
new ManiphestHovercardEventListener(),
|
||||
);
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
final class ManiphestNameIndexEventListener extends PhutilEventListener {
|
||||
|
||||
public function register() {
|
||||
$this->listen(PhabricatorEventType::TYPE_SEARCH_DIDUPDATEINDEX);
|
||||
}
|
||||
|
||||
public function handleEvent(PhutilEvent $event) {
|
||||
$phid = $event->getValue('phid');
|
||||
$type = phid_get_type($phid);
|
||||
|
||||
// For now, we only index projects.
|
||||
if ($type != PhabricatorProjectPHIDTypeProject::TYPECONST) {
|
||||
return;
|
||||
}
|
||||
|
||||
$document = $event->getValue('document');
|
||||
|
||||
ManiphestNameIndex::updateIndex(
|
||||
$phid,
|
||||
$document->getDocumentTitle());
|
||||
}
|
||||
|
||||
}
|
30
src/applications/maniphest/storage/ManiphestNameIndex.php
Normal file
30
src/applications/maniphest/storage/ManiphestNameIndex.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Denormalizes object names to support queries which need to be ordered or
|
||||
* grouped by things like projects.
|
||||
*/
|
||||
final class ManiphestNameIndex extends ManiphestDAO {
|
||||
|
||||
protected $indexedObjectPHID;
|
||||
protected $indexedObjectName;
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_TIMESTAMPS => false,
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public static function updateIndex($phid, $name) {
|
||||
$table = new ManiphestNameIndex();
|
||||
$conn_w = $table->establishConnection('w');
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'INSERT INTO %T (indexedObjectPHID, indexedObjectName) VALUES (%s, %s)
|
||||
ON DUPLICATE KEY UPDATE indexedObjectName = VALUES(indexedObjectName)',
|
||||
$table->getTableName(),
|
||||
$phid,
|
||||
$name);
|
||||
}
|
||||
|
||||
}
|
|
@ -166,6 +166,9 @@ final class PhabricatorProjectEditor extends PhabricatorEditor {
|
|||
throw $ex;
|
||||
}
|
||||
|
||||
id(new PhabricatorSearchIndexer())
|
||||
->indexDocumentByPHID($project->getPHID());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -1580,6 +1580,14 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
|||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('20130912.maniphest.2.created.sql'),
|
||||
),
|
||||
'20130912.maniphest.3.nameindex.sql' => array(
|
||||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('20130912.maniphest.3.nameindex.sql'),
|
||||
),
|
||||
'20130912.maniphest.4.fillindex.php' => array(
|
||||
'type' => 'php',
|
||||
'name' => $this->getPatchPath('20130912.maniphest.4.fillindex.php'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue