1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-20 13:52:40 +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:
epriestley 2014-01-14 13:22:56 -08:00
parent e4deb7faad
commit a716fe99f3
13 changed files with 49 additions and 23 deletions

View file

@ -1900,6 +1900,7 @@ phutil_register_library_map(array(
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
'PhabricatorSearchScope' => 'applications/search/constants/PhabricatorSearchScope.php',
'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php',
'PhabricatorSearchWorker' => 'applications/search/worker/PhabricatorSearchWorker.php',
'PhabricatorSecurityConfigOptions' => 'applications/config/option/PhabricatorSecurityConfigOptions.php',
'PhabricatorSendGridConfigOptions' => 'applications/config/option/PhabricatorSendGridConfigOptions.php',
'PhabricatorSettingsAdjustController' => 'applications/settings/controller/PhabricatorSettingsAdjustController.php',
@ -4543,6 +4544,7 @@ phutil_register_library_map(array(
'PhabricatorSearchQuery' => 'PhabricatorSearchDAO',
'PhabricatorSearchResultView' => 'AphrontView',
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchWorker' => 'PhabricatorWorker',
'PhabricatorSecurityConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorSendGridConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorSettingsAdjustController' => 'PhabricatorController',

View file

@ -302,7 +302,7 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
$this->publishFeedStory($comment, $feed_phids);
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($commit->getPHID());
->queueDocumentForIndexing($commit->getPHID());
if (!$this->noEmail) {
$this->sendMail($comment, $other_comments, $inline_comments, $requests);

View file

@ -700,7 +700,7 @@ final class DifferentialCommentEditor extends PhabricatorEditor {
->publish();
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($revision->getPHID());
->queueDocumentForIndexing($revision->getPHID());
return $comment;
}

View file

@ -534,7 +534,7 @@ final class DifferentialRevisionEditor extends PhabricatorEditor {
->publish();
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($revision->getPHID());
->queueDocumentForIndexing($revision->getPHID());
}
public static function addCCAndUpdateRevision(

View file

@ -45,7 +45,7 @@ final class DiffusionCommitEditController extends DiffusionController {
$editor->save();
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($commit->getPHID());
->queueDocumentForIndexing($commit->getPHID());
return id(new AphrontRedirectResponse())
->setURI('/r'.$callsign.$commit->getCommitIdentifier());

View file

@ -152,7 +152,7 @@ final class PhabricatorUser
$this->updateNameTokens();
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($this->getPHID());
->queueDocumentForIndexing($this->getPHID());
return $result;
}

View file

@ -213,7 +213,7 @@ final class PhrictionDocumentEditor extends PhabricatorEditor {
$document->attachContent($new_content);
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($document->getPHID());
->queueDocumentForIndexing($document->getPHID());
// Stub out empty parent documents if they don't exist
$ancestral_slugs = PhabricatorSlug::getAncestry($document->getSlug());

View file

@ -168,7 +168,7 @@ final class PhabricatorProjectEditor extends PhabricatorEditor {
}
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($project->getPHID());
->queueDocumentForIndexing($project->getPHID());
return $this;
}

View file

@ -87,7 +87,7 @@ abstract class PhabricatorRepositoryCommitChangeParserWorker
PhabricatorRepositoryCommit::IMPORTED_CHANGE);
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($commit->getPHID());
->queueDocumentForIndexing($commit->getPHID());
PhabricatorOwnersPackagePathValidator::updateOwnersPackagePaths($commit);
if ($this->shouldQueueFollowupTasks()) {

View file

@ -1,10 +1,15 @@
<?php
/**
* @group search
*/
final class PhabricatorSearchIndexer {
public function queueDocumentForIndexing($phid) {
PhabricatorWorker::scheduleTask(
'PhabricatorSearchWorker',
array(
'documentPHID' => $phid,
));
}
public function indexDocumentByPHID($phid) {
$doc_indexer_symbols = id(new PhutilSymbolLoader())
->setAncestorClass('PhabricatorSearchDocumentIndexer')

View file

@ -28,13 +28,8 @@ final class PhabricatorSearchManagementIndexWorkflow
array(
'name' => 'background',
'help' => 'Instead of indexing in this process, queue tasks for '.
'the daemons. This is better if you are indexing a lot '.
'of stuff, but less helpful for debugging.',
),
array(
'name' => 'foreground',
'help' => 'Index in this process, even if there are many objects '.
'to index. This is helpful for debugging.',
'the daemons. This can improve performance, but makes '.
'it more difficult to debug search indexing.',
),
array(
'name' => 'objects',
@ -51,7 +46,6 @@ final class PhabricatorSearchManagementIndexWorkflow
$obj_names = $args->getArg('objects');
if ($obj_names && ($is_all || $is_type)) {
throw new PhutilArgumentUsageException(
"You can not name objects to index alongside the '--all' or '--type' ".
@ -72,19 +66,31 @@ final class PhabricatorSearchManagementIndexWorkflow
"Nothing to index!");
}
if ($args->getArg('background')) {
$is_background = true;
} else {
PhabricatorWorker::setRunAllTasksInProcess(true);
$is_background = false;
}
$groups = phid_group_by_type($phids);
foreach ($groups as $group_type => $group) {
$console->writeOut(
"%s\n",
pht(
"Indexing %d object(s) of type %s.",
count($group),
$group_type)."\n");
$group_type));
}
$indexer = new PhabricatorSearchIndexer();
foreach ($phids as $phid) {
$indexer->indexDocumentByPHID($phid);
$console->writeOut(pht("Indexing '%s'...\n", $phid));
if ($is_background) {
$console->writeOut("%s\n", pht("Queueing '%s'...", $phid));
} else {
$console->writeOut("%s\n", pht("Indexing '%s'...", $phid));
}
$indexer->queueDocumentForIndexing($phid);
}
$console->writeOut("Done.\n");

View 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);
}
}

View file

@ -533,7 +533,7 @@ abstract class PhabricatorApplicationTransactionEditor
if ($this->supportsSearch()) {
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($object->getPHID());
->queueDocumentForIndexing($object->getPHID());
}
if ($this->supportsFeed()) {