diff --git a/Changes b/Changes index 9a278efdc..df636dac6 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,7 @@ next: - add support for base64 encoded obfuscate pattern - reworked status page column editor - improve performance when having custom column layout on status pages + - reduce required queries when using lmd - Rest: - add support for host/service note commands ex.: /hosts//cmd/note diff --git a/lib/Thruk/Action/AddDefaults.pm b/lib/Thruk/Action/AddDefaults.pm index 229a3c2bb..39311f4a4 100644 --- a/lib/Thruk/Action/AddDefaults.pm +++ b/lib/Thruk/Action/AddDefaults.pm @@ -638,6 +638,11 @@ sub add_defaults { ############################### $c->stash->{'has_lmd'} = $c->config->{'use_lmd_core'} ? 1 : 0; + if($c->stash->{'has_lmd'}) { + ## no critic + $ENV{'THRUK_LMD_VERSION'} = Thruk::Utils::LMD::get_lmd_version($c->config) unless $ENV{'THRUK_LMD_VERSION'}; + ## use critic + } $c->stash->{'has_expire_acks'} = $c->config->{'has_expire_acks'} // 1; $c->stash->{'require_comments_for_disable_cmds'} = $c->config->{'require_comments_for_disable_cmds'} || 0; diff --git a/lib/Thruk/Utils/Status.pm b/lib/Thruk/Utils/Status.pm index 84030671d..fd3039545 100644 --- a/lib/Thruk/Utils/Status.pm +++ b/lib/Thruk/Utils/Status.pm @@ -1729,13 +1729,28 @@ sub get_comments_filter { return(\@hostfilter, \@servicefilter) unless Thruk::Utils::is_valid_regular_expression( $c, $value ); my $num; - if($value eq '') { + + # LMD can simple search comments and downtimes, no need for a subquery (since version 2.2.2) + if($ENV{'THRUK_USE_LMD'} && Thruk::Utils::version_compare($ENV{'THRUK_LMD_VERSION'}, '2.2.2')) { + if($op eq '=' or $op eq '~~') { + push @hostfilter, { -or => [ comments_with_info => { $op => $value }, downtimes_with_info => { $op => $value } ]}; + push @servicefilter, { -or => [ host_comments_with_info => { $op => $value }, comments_with_info => { $op => $value }, + host_downtimes_with_info => { $op => $value }, downtimes_with_info => { $op => $value } ]}; + } else { + push @hostfilter, { -and => [ comments_with_info => { $op => $value }, downtimes_with_info => { $op => $value } ]}; + push @servicefilter, { -and => [ host_comments_with_info => { $op => $value }, comments_with_info => { $op => $value }, + host_downtimes_with_info => { $op => $value }, downtimes_with_info => { $op => $value } ]}; + } + } + elsif($value eq '') { if($op eq '=' or $op eq '~~') { push @hostfilter, { -and => [ comments => { $op => undef }, downtimes => { $op => undef } ]}; - push @servicefilter, { -and => [ comments => { $op => undef }, downtimes => { $op => undef } ]}; + push @servicefilter, { -and => [ host_comments => { $op => undef }, comments => { $op => undef }, + host_downtimes => { $op => undef }, downtimes => { $op => undef } ]}; } else { push @hostfilter, { -or => [ comments => { $op => { '!=' => undef }}, downtimes => { $op => { '!=' => undef }} ]}; - push @servicefilter, { -or => [ comments => { $op => { '!=' => undef }}, downtimes => { $op => { '!=' => undef }} ]}; + push @servicefilter, { -or => [ host_comments => { $op => { '!=' => undef }}, comments => { $op => { '!=' => undef }}, + host_downtimes => { $op => { '!=' => undef }}, downtimes => { $op => { '!=' => undef }} ]}; } } else {