Skip to content

Commit ecc3314

Browse files
author
epriestley
committedDec 22, 2015
Modularize transaction/comment indexing in the FulltextEngine
Summary: Ref T9979. This is currently hard-coded but can be done in a generic way. This has one minor behavioral changes: answer text is no longer included in the question text index in Ponder. I'm not planning to accommodate that for now since I don't want to dig this hole any deeper than I already have. This behavior should be different anyway (e.g., index the answer, then show the question in the results or something). Test Plan: - Put a unique word in a Maniphest comment. - Searched for the word. - Found the task. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9979 Differential Revision: https://secure.phabricator.com/D14837
1 parent aab1574 commit ecc3314

15 files changed

+80
-115
lines changed
 

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,7 @@
32423242
'PhabricatorTransactions' => 'applications/transactions/constants/PhabricatorTransactions.php',
32433243
'PhabricatorTransactionsApplication' => 'applications/transactions/application/PhabricatorTransactionsApplication.php',
32443244
'PhabricatorTransactionsDestructionEngineExtension' => 'applications/transactions/engineextension/PhabricatorTransactionsDestructionEngineExtension.php',
3245+
'PhabricatorTransactionsFulltextEngineExtension' => 'applications/transactions/engineextension/PhabricatorTransactionsFulltextEngineExtension.php',
32453246
'PhabricatorTransformedFile' => 'applications/files/storage/PhabricatorTransformedFile.php',
32463247
'PhabricatorTranslationsConfigOptions' => 'applications/config/option/PhabricatorTranslationsConfigOptions.php',
32473248
'PhabricatorTriggerAction' => 'infrastructure/daemon/workers/action/PhabricatorTriggerAction.php',
@@ -7614,6 +7615,7 @@
76147615
'PhabricatorTransactions' => 'Phobject',
76157616
'PhabricatorTransactionsApplication' => 'PhabricatorApplication',
76167617
'PhabricatorTransactionsDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
7618+
'PhabricatorTransactionsFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension',
76177619
'PhabricatorTransformedFile' => 'PhabricatorFileDAO',
76187620
'PhabricatorTranslationsConfigOptions' => 'PhabricatorApplicationConfigOptions',
76197621
'PhabricatorTriggerAction' => 'Phobject',

‎src/applications/calendar/search/PhabricatorCalendarEventSearchIndexer.php

-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ protected function buildAbstractDocumentByPHID($phid) {
4141
PhabricatorCalendarEventPHIDType::TYPECONST,
4242
time());
4343

44-
$this->indexTransactions(
45-
$doc,
46-
new PhabricatorCalendarEventTransactionQuery(),
47-
array($phid));
48-
4944
return $doc;
5045
}
5146

‎src/applications/differential/search/DifferentialSearchIndexer.php

-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ protected function buildAbstractDocumentByPHID($phid) {
4343
DifferentialRevisionPHIDType::TYPECONST,
4444
time());
4545

46-
$this->indexTransactions(
47-
$doc,
48-
new DifferentialTransactionQuery(),
49-
array($rev->getPHID()));
50-
5146
// If a revision needs review, the owners are the reviewers. Otherwise, the
5247
// owner is the author (e.g., accepted, rejected, closed).
5348
if ($rev->getStatus() == ArcanistDifferentialRevisionStatus::NEEDS_REVIEW) {

‎src/applications/diviner/search/DivinerBookSearchIndexer.php

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ protected function buildAbstractDocumentByPHID($phid) {
2424
PhabricatorRepositoryRepositoryPHIDType::TYPECONST,
2525
$book->getDateCreated());
2626

27-
$this->indexTransactions(
28-
$doc,
29-
new DivinerLiveBookTransactionQuery(),
30-
array($phid));
31-
3227
return $doc;
3328
}
3429

‎src/applications/fund/search/FundInitiativeIndexer.php

-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ protected function buildAbstractDocumentByPHID($phid) {
5151
FundInitiativePHIDType::TYPECONST,
5252
time());
5353

54-
$this->indexTransactions(
55-
$doc,
56-
new FundInitiativeTransactionQuery(),
57-
array($initiative->getPHID()));
58-
5954
return $doc;
6055
}
6156
}

‎src/applications/maniphest/search/ManiphestSearchIndexer.php

-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ protected function buildAbstractDocumentByPHID($phid) {
3434
ManiphestTaskPHIDType::TYPECONST,
3535
time());
3636

37-
$this->indexTransactions(
38-
$doc,
39-
new ManiphestTransactionQuery(),
40-
array($phid));
41-
4237
$owner = $task->getOwnerPHID();
4338
if ($owner) {
4439
$doc->addRelationship(

‎src/applications/passphrase/search/PassphraseSearchIndexer.php

-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ protected function buildAbstractDocumentByPHID($phid) {
2828
PassphraseCredentialPHIDType::TYPECONST,
2929
time());
3030

31-
$this->indexTransactions(
32-
$doc,
33-
new PassphraseCredentialTransactionQuery(),
34-
array($phid));
35-
3631
return $doc;
3732
}
3833

‎src/applications/pholio/search/PholioSearchIndexer.php

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ protected function buildAbstractDocumentByPHID($phid) {
2424
PhabricatorPeopleUserPHIDType::TYPECONST,
2525
$mock->getDateCreated());
2626

27-
$this->indexTransactions(
28-
$doc,
29-
new PholioTransactionQuery(),
30-
array($phid));
31-
3227
return $doc;
3328
}
3429

‎src/applications/ponder/search/PonderSearchIndexer.php

-9
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ protected function buildAbstractDocumentByPHID($phid) {
3737
}
3838
}
3939

40-
$this->indexTransactions(
41-
$doc,
42-
new PonderQuestionTransactionQuery(),
43-
array($phid));
44-
$this->indexTransactions(
45-
$doc,
46-
new PonderAnswerTransactionQuery(),
47-
mpull($answers, 'getPHID'));
48-
4940
return $doc;
5041
}
5142
}

‎src/applications/repository/search/PhabricatorRepositoryCommitSearchIndexer.php

-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ protected function buildAbstractDocumentByPHID($phid) {
5353
PhabricatorRepositoryRepositoryPHIDType::TYPECONST,
5454
$date_created);
5555

56-
$this->indexTransactions(
57-
$doc,
58-
new PhabricatorAuditTransactionQuery(),
59-
array($commit->getPHID()));
60-
6156
return $doc;
6257
}
6358
}

‎src/applications/search/index/PhabricatorSearchDocumentIndexer.php

-22
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,4 @@ protected function newDocument($phid) {
7575
->setDocumentType(phid_get_type($phid));
7676
}
7777

78-
protected function indexTransactions(
79-
PhabricatorSearchAbstractDocument $doc,
80-
PhabricatorApplicationTransactionQuery $query,
81-
array $phids) {
82-
83-
$xactions = id(clone $query)
84-
->setViewer($this->getViewer())
85-
->withObjectPHIDs($phids)
86-
->execute();
87-
88-
foreach ($xactions as $xaction) {
89-
if (!$xaction->hasComment()) {
90-
continue;
91-
}
92-
93-
$comment = $xaction->getComment();
94-
$doc->addField(
95-
PhabricatorSearchDocumentFieldType::FIELD_COMMENT,
96-
$comment->getContent());
97-
}
98-
}
99-
10078
}

‎src/applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php

+4-17
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,17 @@ public function handleRequest(AphrontRequest $request) {
1717
if (!$object) {
1818
return new Aphront404Response();
1919
}
20+
2021
if (!$object instanceof PhabricatorApplicationTransactionInterface) {
2122
return new Aphront404Response();
2223
}
2324

24-
$template = $object->getApplicationTransactionTemplate();
25-
$queries = id(new PhutilClassMapQuery())
26-
->setAncestorClass('PhabricatorApplicationTransactionQuery')
27-
->execute();
28-
29-
$object_query = null;
30-
foreach ($queries as $query) {
31-
if ($query->getTemplateApplicationTransaction() == $template) {
32-
$object_query = $query;
33-
break;
34-
}
35-
}
36-
37-
if (!$object_query) {
25+
$query = PhabricatorApplicationTransactionQuery::newQueryForObject($object);
26+
if (!$query) {
3827
return new Aphront404Response();
3928
}
4029

41-
$timeline = $this->buildTransactionTimeline(
42-
$object,
43-
$query);
30+
$timeline = $this->buildTransactionTimeline($object, $query);
4431

4532
$phui_timeline = $timeline->buildPHUITimelineView($with_hiding = false);
4633
$phui_timeline->setShouldAddSpacers(false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
final class PhabricatorTransactionsFulltextEngineExtension
4+
extends PhabricatorFulltextEngineExtension {
5+
6+
const EXTENSIONKEY = 'transactions';
7+
8+
public function getExtensionName() {
9+
return pht('Comments');
10+
}
11+
12+
public function shouldIndexFulltextObject($object) {
13+
return ($object instanceof PhabricatorApplicationTransactionInterface);
14+
}
15+
16+
public function indexFulltextObject(
17+
$object,
18+
PhabricatorSearchAbstractDocument $document) {
19+
20+
$query = PhabricatorApplicationTransactionQuery::newQueryForObject($object);
21+
if (!$query) {
22+
return;
23+
}
24+
25+
$xactions = $query
26+
->setViewer($this->getViewer())
27+
->withObjectPHIDs(array($object->getPHID()))
28+
->needComments(true)
29+
->execute();
30+
31+
foreach ($xactions as $xaction) {
32+
if (!$xaction->hasComment()) {
33+
continue;
34+
}
35+
36+
$comment = $xaction->getComment();
37+
38+
$document->addField(
39+
PhabricatorSearchDocumentFieldType::FIELD_COMMENT,
40+
$comment->getContent());
41+
}
42+
}
43+
44+
}

‎src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ abstract class PhabricatorApplicationTransactionQuery
1111
private $needComments = true;
1212
private $needHandles = true;
1313

14+
final public static function newQueryForObject(
15+
PhabricatorApplicationTransactionInterface $object) {
16+
17+
$xaction = $object->getApplicationTransactionTemplate();
18+
$target_class = get_class($xaction);
19+
20+
$queries = id(new PhutilClassMapQuery())
21+
->setAncestorClass(__CLASS__)
22+
->execute();
23+
foreach ($queries as $query) {
24+
$query_xaction = $query->getTemplateApplicationTransaction();
25+
$query_class = get_class($query_xaction);
26+
27+
if ($query_class === $target_class) {
28+
return id(clone $query);
29+
}
30+
}
31+
32+
return null;
33+
}
34+
1435
abstract public function getTemplateApplicationTransaction();
1536

1637
protected function buildMoreWhereClauses(AphrontDatabaseConnection $conn_r) {

‎src/applications/transactions/worker/PhabricatorApplicationTransactionPublishWorker.php

+9-27
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ private function loadTransactions(
9292

9393
$viewer = PhabricatorUser::getOmnipotentUser();
9494

95-
$type = phid_get_subtype(head($xaction_phids));
96-
$xactions = $this->buildTransactionQuery($type)
95+
$query = PhabricatorApplicationTransactionQuery::newQueryForObject($object);
96+
if (!$query) {
97+
throw new PhabricatorWorkerPermanentFailureException(
98+
pht(
99+
'Unable to load query for transaction object "%s"!',
100+
$object->getPHID()));
101+
}
102+
103+
$xactions = $query
97104
->setViewer($viewer)
98105
->withPHIDs($xaction_phids)
99106
->needComments(true)
@@ -111,29 +118,4 @@ private function loadTransactions(
111118
return array_select_keys($xactions, $xaction_phids);
112119
}
113120

114-
115-
/**
116-
* Build a new transaction query of the appropriate class so we can load
117-
* the transactions.
118-
*/
119-
private function buildTransactionQuery($type) {
120-
$queries = id(new PhutilClassMapQuery())
121-
->setAncestorClass('PhabricatorApplicationTransactionQuery')
122-
->execute();
123-
124-
foreach ($queries as $query) {
125-
$query_type = $query
126-
->getTemplateApplicationTransaction()
127-
->getApplicationTransactionType();
128-
if ($query_type == $type) {
129-
return $query;
130-
}
131-
}
132-
133-
throw new PhabricatorWorkerPermanentFailureException(
134-
pht(
135-
'Unable to load query for transaction type "%s"!',
136-
$type));
137-
}
138-
139121
}

0 commit comments

Comments
 (0)
Failed to load comments.