Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / transactions / engineextension / PhabricatorTransactionsFulltextEngineExtension.php
blob4eeda3251c52c503fa1670e92814593c57a857ef
1 <?php
3 final class PhabricatorTransactionsFulltextEngineExtension
4 extends PhabricatorFulltextEngineExtension {
6 const EXTENSIONKEY = 'transactions';
8 public function getExtensionName() {
9 return pht('Comments');
12 public function shouldEnrichFulltextObject($object) {
13 return ($object instanceof PhabricatorApplicationTransactionInterface);
16 public function enrichFulltextObject(
17 $object,
18 PhabricatorSearchAbstractDocument $document) {
20 $query = PhabricatorApplicationTransactionQuery::newQueryForObject($object);
21 if (!$query) {
22 return;
25 $query
26 ->setViewer($this->getViewer())
27 ->withObjectPHIDs(array($object->getPHID()))
28 ->withComments(true)
29 ->needComments(true);
31 // See PHI719. Users occasionally create objects with huge numbers of
32 // comments, which can be slow to index. We handle this with reasonable
33 // grace: at time of writing, we can index a task with 100K comments in
34 // about 30 seconds. However, we do need to hold all the comments in
35 // memory in the AbstractDocument, so there's some practical limit to what
36 // we can realistically index.
38 // Since objects with more than 1,000 comments are not likely to be
39 // legitimate objects with actual discussion, index only the first
40 // thousand comments.
42 $query
43 ->setOrderVector(array('-id'))
44 ->setLimit(1000);
46 $xactions = $query->execute();
48 foreach ($xactions as $xaction) {
49 if (!$xaction->hasComment()) {
50 continue;
53 $comment = $xaction->getComment();
55 $document->addField(
56 PhabricatorSearchDocumentFieldType::FIELD_COMMENT,
57 $comment->getContent());