Commit ad6c82a3 authored by Victor Emanouilov's avatar Victor Emanouilov

[FIX] performance optimization - don't load missing relation field remote item...

[FIX] performance optimization - don't load missing relation field remote item titles when formatting results for the search index - only do this while indexing; this prevents circular references, looping over and over the path Relation::getDocumentPart->related objects->get_title; it also drastically decreases the number of search index queries when there are many inter-related items
parent 7c9954ab
Pipeline #50205002 failed with stages
in 31 minutes and 51 seconds
......@@ -9,11 +9,13 @@ class Search_ContentSource_TrackerItemSource implements Search_ContentSource_Int
{
private $db;
private $trklib;
private $mode;
function __construct()
function __construct($mode = '')
{
$this->db = TikiDb::get();
$this->trklib = TikiLib::lib('trk');
$this->mode = $mode;
}
function getReferenceMap()
......@@ -60,7 +62,7 @@ class Search_ContentSource_TrackerItemSource implements Search_ContentSource_Int
}
foreach (self::getIndexableHandlers($definition, $item) as $handler) {
$data = array_merge($data, $handler->getDocumentPart($typeFactory));
$data = array_merge($data, $handler->getDocumentPart($typeFactory, $this->mode));
}
$ownerGroup = $itemObject->getOwnerGroup();
......
......@@ -484,7 +484,7 @@ class Tracker_Field_Relation extends Tracker_Field_Abstract
}
}
function getDocumentPart(Search_Type_Factory_Interface $typeFactory)
function getDocumentPart(Search_Type_Factory_Interface $typeFactory, $mode = '')
{
$baseKey = $this->getBaseKey();
......@@ -496,16 +496,18 @@ class Tracker_Field_Relation extends Tracker_Field_Abstract
$format = $this->getOption('format');
$labels = [];
static $called = [];
foreach ($data['relations'] as $identifier) {
list($type, $object) = explode(':', $identifier);
if (in_array($type.$object, $called)) {
// prevent circular-reference calls to objectlib->get_title method as getDocumentPart is used to populate the
// search results with field values which is called in get_title itself
// only happens for bi-directional tracker item relation
continue;
if ($mode !== 'formatting') {
foreach ($data['relations'] as $identifier) {
list($type, $object) = explode(':', $identifier);
if (in_array($type.$object, $called)) {
// prevent circular-reference calls to objectlib->get_title method as getDocumentPart is used to populate the
// search results with field values which is called in get_title itself
// only happens for bi-directional tracker item relation
continue;
}
$called[] = $type.$object;
$labels[] = $objectLib->get_title($type, $object, $format);
}
$called[] = $type.$object;
$labels[] = $objectLib->get_title($type, $object, $format);
}
$plain = implode(', ', $labels);
......
......@@ -598,7 +598,7 @@ class UnifiedSearchLib
}
if (isset($types['trackeritem'])) {
$aggregator->addContentSource('trackeritem', new Search_ContentSource_TrackerItemSource);
$aggregator->addContentSource('trackeritem', new Search_ContentSource_TrackerItemSource($mode));
$aggregator->addContentSource('tracker', new Search_ContentSource_TrackerSource);
$aggregator->addContentSource('trackerfield', new Search_ContentSource_TrackerFieldSource);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment