mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 01:10:58 +01:00
Perform search indexing in the worker queue and respect bin/search index --background
Summary: Fixes T3857. Earlier work made this trivial and just left product questions, which I've answered by requiring the daemons to run on reasonable installs. Test Plan: Ran `bin/search index` and `bin/search index --background`. Observed indexes write in the former case and tasks queue in the latter case. Commented with a unique string on a revision and searched for it a moment later, got exactly one result (that revision), verifying that reindexing works correctly. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3857 Differential Revision: https://secure.phabricator.com/D7966
This commit is contained in:
parent
e4deb7faad
commit
a716fe99f3
13 changed files with 49 additions and 23 deletions
|
@ -1900,6 +1900,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
|
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
|
||||||
'PhabricatorSearchScope' => 'applications/search/constants/PhabricatorSearchScope.php',
|
'PhabricatorSearchScope' => 'applications/search/constants/PhabricatorSearchScope.php',
|
||||||
'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php',
|
'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php',
|
||||||
|
'PhabricatorSearchWorker' => 'applications/search/worker/PhabricatorSearchWorker.php',
|
||||||
'PhabricatorSecurityConfigOptions' => 'applications/config/option/PhabricatorSecurityConfigOptions.php',
|
'PhabricatorSecurityConfigOptions' => 'applications/config/option/PhabricatorSecurityConfigOptions.php',
|
||||||
'PhabricatorSendGridConfigOptions' => 'applications/config/option/PhabricatorSendGridConfigOptions.php',
|
'PhabricatorSendGridConfigOptions' => 'applications/config/option/PhabricatorSendGridConfigOptions.php',
|
||||||
'PhabricatorSettingsAdjustController' => 'applications/settings/controller/PhabricatorSettingsAdjustController.php',
|
'PhabricatorSettingsAdjustController' => 'applications/settings/controller/PhabricatorSettingsAdjustController.php',
|
||||||
|
@ -4543,6 +4544,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSearchQuery' => 'PhabricatorSearchDAO',
|
'PhabricatorSearchQuery' => 'PhabricatorSearchDAO',
|
||||||
'PhabricatorSearchResultView' => 'AphrontView',
|
'PhabricatorSearchResultView' => 'AphrontView',
|
||||||
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
|
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
|
||||||
|
'PhabricatorSearchWorker' => 'PhabricatorWorker',
|
||||||
'PhabricatorSecurityConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorSecurityConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
'PhabricatorSendGridConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorSendGridConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
'PhabricatorSettingsAdjustController' => 'PhabricatorController',
|
'PhabricatorSettingsAdjustController' => 'PhabricatorController',
|
||||||
|
|
|
@ -302,7 +302,7 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
|
||||||
$this->publishFeedStory($comment, $feed_phids);
|
$this->publishFeedStory($comment, $feed_phids);
|
||||||
|
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($commit->getPHID());
|
->queueDocumentForIndexing($commit->getPHID());
|
||||||
|
|
||||||
if (!$this->noEmail) {
|
if (!$this->noEmail) {
|
||||||
$this->sendMail($comment, $other_comments, $inline_comments, $requests);
|
$this->sendMail($comment, $other_comments, $inline_comments, $requests);
|
||||||
|
|
|
@ -700,7 +700,7 @@ final class DifferentialCommentEditor extends PhabricatorEditor {
|
||||||
->publish();
|
->publish();
|
||||||
|
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($revision->getPHID());
|
->queueDocumentForIndexing($revision->getPHID());
|
||||||
|
|
||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
|
@ -534,7 +534,7 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
|
||||||
->publish();
|
->publish();
|
||||||
|
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($revision->getPHID());
|
->queueDocumentForIndexing($revision->getPHID());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function addCCAndUpdateRevision(
|
public static function addCCAndUpdateRevision(
|
||||||
|
|
|
@ -45,7 +45,7 @@ final class DiffusionCommitEditController extends DiffusionController {
|
||||||
$editor->save();
|
$editor->save();
|
||||||
|
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($commit->getPHID());
|
->queueDocumentForIndexing($commit->getPHID());
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/r'.$callsign.$commit->getCommitIdentifier());
|
->setURI('/r'.$callsign.$commit->getCommitIdentifier());
|
||||||
|
|
|
@ -152,7 +152,7 @@ final class PhabricatorUser
|
||||||
$this->updateNameTokens();
|
$this->updateNameTokens();
|
||||||
|
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($this->getPHID());
|
->queueDocumentForIndexing($this->getPHID());
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
|
||||||
$document->attachContent($new_content);
|
$document->attachContent($new_content);
|
||||||
|
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($document->getPHID());
|
->queueDocumentForIndexing($document->getPHID());
|
||||||
|
|
||||||
// Stub out empty parent documents if they don't exist
|
// Stub out empty parent documents if they don't exist
|
||||||
$ancestral_slugs = PhabricatorSlug::getAncestry($document->getSlug());
|
$ancestral_slugs = PhabricatorSlug::getAncestry($document->getSlug());
|
||||||
|
|
|
@ -168,7 +168,7 @@ final class PhabricatorProjectEditor extends PhabricatorEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($project->getPHID());
|
->queueDocumentForIndexing($project->getPHID());
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ abstract class PhabricatorRepositoryCommitChangeParserWorker
|
||||||
PhabricatorRepositoryCommit::IMPORTED_CHANGE);
|
PhabricatorRepositoryCommit::IMPORTED_CHANGE);
|
||||||
|
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($commit->getPHID());
|
->queueDocumentForIndexing($commit->getPHID());
|
||||||
|
|
||||||
PhabricatorOwnersPackagePathValidator::updateOwnersPackagePaths($commit);
|
PhabricatorOwnersPackagePathValidator::updateOwnersPackagePaths($commit);
|
||||||
if ($this->shouldQueueFollowupTasks()) {
|
if ($this->shouldQueueFollowupTasks()) {
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* @group search
|
|
||||||
*/
|
|
||||||
final class PhabricatorSearchIndexer {
|
final class PhabricatorSearchIndexer {
|
||||||
|
|
||||||
|
public function queueDocumentForIndexing($phid) {
|
||||||
|
PhabricatorWorker::scheduleTask(
|
||||||
|
'PhabricatorSearchWorker',
|
||||||
|
array(
|
||||||
|
'documentPHID' => $phid,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public function indexDocumentByPHID($phid) {
|
public function indexDocumentByPHID($phid) {
|
||||||
$doc_indexer_symbols = id(new PhutilSymbolLoader())
|
$doc_indexer_symbols = id(new PhutilSymbolLoader())
|
||||||
->setAncestorClass('PhabricatorSearchDocumentIndexer')
|
->setAncestorClass('PhabricatorSearchDocumentIndexer')
|
||||||
|
|
|
@ -28,13 +28,8 @@ final class PhabricatorSearchManagementIndexWorkflow
|
||||||
array(
|
array(
|
||||||
'name' => 'background',
|
'name' => 'background',
|
||||||
'help' => 'Instead of indexing in this process, queue tasks for '.
|
'help' => 'Instead of indexing in this process, queue tasks for '.
|
||||||
'the daemons. This is better if you are indexing a lot '.
|
'the daemons. This can improve performance, but makes '.
|
||||||
'of stuff, but less helpful for debugging.',
|
'it more difficult to debug search indexing.',
|
||||||
),
|
|
||||||
array(
|
|
||||||
'name' => 'foreground',
|
|
||||||
'help' => 'Index in this process, even if there are many objects '.
|
|
||||||
'to index. This is helpful for debugging.',
|
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'name' => 'objects',
|
'name' => 'objects',
|
||||||
|
@ -51,7 +46,6 @@ final class PhabricatorSearchManagementIndexWorkflow
|
||||||
|
|
||||||
$obj_names = $args->getArg('objects');
|
$obj_names = $args->getArg('objects');
|
||||||
|
|
||||||
|
|
||||||
if ($obj_names && ($is_all || $is_type)) {
|
if ($obj_names && ($is_all || $is_type)) {
|
||||||
throw new PhutilArgumentUsageException(
|
throw new PhutilArgumentUsageException(
|
||||||
"You can not name objects to index alongside the '--all' or '--type' ".
|
"You can not name objects to index alongside the '--all' or '--type' ".
|
||||||
|
@ -72,19 +66,31 @@ final class PhabricatorSearchManagementIndexWorkflow
|
||||||
"Nothing to index!");
|
"Nothing to index!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($args->getArg('background')) {
|
||||||
|
$is_background = true;
|
||||||
|
} else {
|
||||||
|
PhabricatorWorker::setRunAllTasksInProcess(true);
|
||||||
|
$is_background = false;
|
||||||
|
}
|
||||||
|
|
||||||
$groups = phid_group_by_type($phids);
|
$groups = phid_group_by_type($phids);
|
||||||
foreach ($groups as $group_type => $group) {
|
foreach ($groups as $group_type => $group) {
|
||||||
$console->writeOut(
|
$console->writeOut(
|
||||||
|
"%s\n",
|
||||||
pht(
|
pht(
|
||||||
"Indexing %d object(s) of type %s.",
|
"Indexing %d object(s) of type %s.",
|
||||||
count($group),
|
count($group),
|
||||||
$group_type)."\n");
|
$group_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
$indexer = new PhabricatorSearchIndexer();
|
$indexer = new PhabricatorSearchIndexer();
|
||||||
foreach ($phids as $phid) {
|
foreach ($phids as $phid) {
|
||||||
$indexer->indexDocumentByPHID($phid);
|
if ($is_background) {
|
||||||
$console->writeOut(pht("Indexing '%s'...\n", $phid));
|
$console->writeOut("%s\n", pht("Queueing '%s'...", $phid));
|
||||||
|
} else {
|
||||||
|
$console->writeOut("%s\n", pht("Indexing '%s'...", $phid));
|
||||||
|
}
|
||||||
|
$indexer->queueDocumentForIndexing($phid);
|
||||||
}
|
}
|
||||||
|
|
||||||
$console->writeOut("Done.\n");
|
$console->writeOut("Done.\n");
|
||||||
|
|
13
src/applications/search/worker/PhabricatorSearchWorker.php
Normal file
13
src/applications/search/worker/PhabricatorSearchWorker.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorSearchWorker extends PhabricatorWorker {
|
||||||
|
|
||||||
|
public function doWork() {
|
||||||
|
$data = $this->getTaskData();
|
||||||
|
$phid = idx($data, 'documentPHID');
|
||||||
|
|
||||||
|
id(new PhabricatorSearchIndexer())
|
||||||
|
->indexDocumentByPHID($phid);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -533,7 +533,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
|
|
||||||
if ($this->supportsSearch()) {
|
if ($this->supportsSearch()) {
|
||||||
id(new PhabricatorSearchIndexer())
|
id(new PhabricatorSearchIndexer())
|
||||||
->indexDocumentByPHID($object->getPHID());
|
->queueDocumentForIndexing($object->getPHID());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->supportsFeed()) {
|
if ($this->supportsFeed()) {
|
||||||
|
|
Loading…
Reference in a new issue