diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0ba6091953..233ce3f309 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/audit/editor/PhabricatorAuditCommentEditor.php b/src/applications/audit/editor/PhabricatorAuditCommentEditor.php index 8eb6ce79fc..ff72c79de3 100644 --- a/src/applications/audit/editor/PhabricatorAuditCommentEditor.php +++ b/src/applications/audit/editor/PhabricatorAuditCommentEditor.php @@ -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); diff --git a/src/applications/differential/editor/DifferentialCommentEditor.php b/src/applications/differential/editor/DifferentialCommentEditor.php index 0fef83eb2d..3884f5c3ae 100644 --- a/src/applications/differential/editor/DifferentialCommentEditor.php +++ b/src/applications/differential/editor/DifferentialCommentEditor.php @@ -700,7 +700,7 @@ final class DifferentialCommentEditor extends PhabricatorEditor { ->publish(); id(new PhabricatorSearchIndexer()) - ->indexDocumentByPHID($revision->getPHID()); + ->queueDocumentForIndexing($revision->getPHID()); return $comment; } diff --git a/src/applications/differential/editor/DifferentialRevisionEditor.php b/src/applications/differential/editor/DifferentialRevisionEditor.php index beefc3f114..bf3d82068c 100644 --- a/src/applications/differential/editor/DifferentialRevisionEditor.php +++ b/src/applications/differential/editor/DifferentialRevisionEditor.php @@ -534,7 +534,7 @@ final class DifferentialRevisionEditor extends PhabricatorEditor { ->publish(); id(new PhabricatorSearchIndexer()) - ->indexDocumentByPHID($revision->getPHID()); + ->queueDocumentForIndexing($revision->getPHID()); } public static function addCCAndUpdateRevision( diff --git a/src/applications/diffusion/controller/DiffusionCommitEditController.php b/src/applications/diffusion/controller/DiffusionCommitEditController.php index 13e78ea1a0..9d1024c60c 100644 --- a/src/applications/diffusion/controller/DiffusionCommitEditController.php +++ b/src/applications/diffusion/controller/DiffusionCommitEditController.php @@ -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()); diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index b94b26644e..bb85d064e9 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -152,7 +152,7 @@ final class PhabricatorUser $this->updateNameTokens(); id(new PhabricatorSearchIndexer()) - ->indexDocumentByPHID($this->getPHID()); + ->queueDocumentForIndexing($this->getPHID()); return $result; } diff --git a/src/applications/phriction/editor/PhrictionDocumentEditor.php b/src/applications/phriction/editor/PhrictionDocumentEditor.php index 06042fcc9a..d0ca728e89 100644 --- a/src/applications/phriction/editor/PhrictionDocumentEditor.php +++ b/src/applications/phriction/editor/PhrictionDocumentEditor.php @@ -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()); diff --git a/src/applications/project/editor/PhabricatorProjectEditor.php b/src/applications/project/editor/PhabricatorProjectEditor.php index 192846ec69..05f01db9e4 100644 --- a/src/applications/project/editor/PhabricatorProjectEditor.php +++ b/src/applications/project/editor/PhabricatorProjectEditor.php @@ -168,7 +168,7 @@ final class PhabricatorProjectEditor extends PhabricatorEditor { } id(new PhabricatorSearchIndexer()) - ->indexDocumentByPHID($project->getPHID()); + ->queueDocumentForIndexing($project->getPHID()); return $this; } diff --git a/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php b/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php index 35d88d2eca..bcd8f859f6 100644 --- a/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php +++ b/src/applications/repository/worker/commitchangeparser/PhabricatorRepositoryCommitChangeParserWorker.php @@ -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()) { diff --git a/src/applications/search/index/PhabricatorSearchIndexer.php b/src/applications/search/index/PhabricatorSearchIndexer.php index b6c2b13efb..2f67a10b93 100644 --- a/src/applications/search/index/PhabricatorSearchIndexer.php +++ b/src/applications/search/index/PhabricatorSearchIndexer.php @@ -1,10 +1,15 @@ $phid, + )); + } + public function indexDocumentByPHID($phid) { $doc_indexer_symbols = id(new PhutilSymbolLoader()) ->setAncestorClass('PhabricatorSearchDocumentIndexer') diff --git a/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php b/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php index 3eb33c1b2b..dd608cd444 100644 --- a/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php +++ b/src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php @@ -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"); diff --git a/src/applications/search/worker/PhabricatorSearchWorker.php b/src/applications/search/worker/PhabricatorSearchWorker.php new file mode 100644 index 0000000000..15179da6e5 --- /dev/null +++ b/src/applications/search/worker/PhabricatorSearchWorker.php @@ -0,0 +1,13 @@ +getTaskData(); + $phid = idx($data, 'documentPHID'); + + id(new PhabricatorSearchIndexer()) + ->indexDocumentByPHID($phid); + } + +} diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index fe78486033..9046988de1 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -533,7 +533,7 @@ abstract class PhabricatorApplicationTransactionEditor if ($this->supportsSearch()) { id(new PhabricatorSearchIndexer()) - ->indexDocumentByPHID($object->getPHID()); + ->queueDocumentForIndexing($object->getPHID()); } if ($this->supportsFeed()) {