From 8779f9f1758c7245625e9b52c41b3cf5664017f3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 23 Feb 2022 14:35:59 +0100 Subject: [PATCH] IdoQuery: Join customvars with only live references --- .../Monitoring/Backend/Ido/Query/IdoQuery.php | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index c925191ae..0fcfc4247 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -1193,14 +1193,31 @@ abstract class IdoQuery extends DbQuery $this->customVars[strtolower($customvar)] = $alias; - if ($this->hasJoinedVirtualTable('services')) { - $leftcol = 's.' . $type . '_object_id'; - } elseif ($type === 'service') { - $this->requireVirtualTable('services'); - $leftcol = 's.service_object_id'; - } else { - $this->requireVirtualTable('hosts'); - $leftcol = 'h.host_object_id'; + if ($type === 'host') { + if ( + $this instanceof ServicecommentQuery + || $this instanceof ServicedowntimeQuery + || $this instanceof ServicecommenthistoryQuery + || $this instanceof ServicedowntimestarthistoryQuery + || $this instanceof ServiceflappingstarthistoryQuery + || $this instanceof ServicegroupQuery + || $this instanceof ServicenotificationQuery + || $this instanceof ServicestatehistoryQuery + || $this instanceof ServicestatusQuery + ) { + $this->requireVirtualTable('services'); + $leftcol = 's.host_object_id'; + } else { + $leftcol = 'ho.object_id'; + if (! $this->hasJoinedTable('ho')) { + $this->requireVirtualTable('hosts'); + } + } + } else { // $type === 'service' + $leftcol = 'so.object_id'; + if (! $this->hasJoinedTable('so')) { + $this->requireVirtualTable('services'); + } } $mapped = $this->getMappedField($leftcol);