2015-12-21 16:08:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorTransactionsFulltextEngineExtension
|
|
|
|
extends PhabricatorFulltextEngineExtension {
|
|
|
|
|
|
|
|
const EXTENSIONKEY = 'transactions';
|
|
|
|
|
|
|
|
public function getExtensionName() {
|
|
|
|
return pht('Comments');
|
|
|
|
}
|
|
|
|
|
2017-09-01 18:19:01 +02:00
|
|
|
public function shouldEnrichFulltextObject($object) {
|
2015-12-21 16:08:17 +01:00
|
|
|
return ($object instanceof PhabricatorApplicationTransactionInterface);
|
|
|
|
}
|
|
|
|
|
2017-09-01 18:19:01 +02:00
|
|
|
public function enrichFulltextObject(
|
2015-12-21 16:08:17 +01:00
|
|
|
$object,
|
|
|
|
PhabricatorSearchAbstractDocument $document) {
|
|
|
|
|
|
|
|
$query = PhabricatorApplicationTransactionQuery::newQueryForObject($object);
|
|
|
|
if (!$query) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-22 16:21:24 +02:00
|
|
|
$query
|
2015-12-21 16:08:17 +01:00
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withObjectPHIDs(array($object->getPHID()))
|
2017-09-28 21:48:19 +02:00
|
|
|
->withComments(true)
|
2018-06-22 16:21:24 +02:00
|
|
|
->needComments(true);
|
|
|
|
|
|
|
|
// See PHI719. Users occasionally create objects with huge numbers of
|
|
|
|
// comments, which can be slow to index. We handle this with reasonable
|
|
|
|
// grace: at time of writing, we can index a task with 100K comments in
|
|
|
|
// about 30 seconds. However, we do need to hold all the comments in
|
|
|
|
// memory in the AbstractDocument, so there's some practical limit to what
|
|
|
|
// we can realistically index.
|
|
|
|
|
|
|
|
// Since objects with more than 1,000 comments are not likely to be
|
|
|
|
// legitimate objects with actual discussion, index only the first
|
|
|
|
// thousand comments.
|
|
|
|
|
|
|
|
$query
|
|
|
|
->setOrderVector(array('-id'))
|
|
|
|
->setLimit(1000);
|
|
|
|
|
|
|
|
$xactions = $query->execute();
|
2015-12-21 16:08:17 +01:00
|
|
|
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
if (!$xaction->hasComment()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$comment = $xaction->getComment();
|
|
|
|
|
|
|
|
$document->addField(
|
|
|
|
PhabricatorSearchDocumentFieldType::FIELD_COMMENT,
|
|
|
|
$comment->getContent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|