From 48af679cf0695e846085966eb293cd7f84041478 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 21 Apr 2023 16:03:58 +0200 Subject: [PATCH] IcingaObjectGroup: membership calculation... ...is now being triggered only when assign_filter exists / has been changed fixes #2048 --- doc/82-Changelog.md | 4 +++ library/Director/Objects/IcingaHostGroup.php | 8 ++--- .../Director/Objects/IcingaObjectGroup.php | 31 +++++++++++++++++++ .../Director/Objects/IcingaServiceGroup.php | 8 ++--- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 5c1f0984..f48c9a5d 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -34,6 +34,10 @@ This version hasn't been released yet ### Health Check * FIX: complaint about overdue jobs was not correct (#2680, #2681) +### Internals + +* FIX: group membership is no longer resolved when not needed (#2048) + ### Fixed issues * You can find issues and feature requests related to this release on our [roadmap](https://github.com/Icinga/icingaweb2-module-director/milestone/33?closed=1) diff --git a/library/Director/Objects/IcingaHostGroup.php b/library/Director/Objects/IcingaHostGroup.php index e11f672e..e78e9319 100644 --- a/library/Director/Objects/IcingaHostGroup.php +++ b/library/Director/Objects/IcingaHostGroup.php @@ -31,12 +31,8 @@ class IcingaHostGroup extends IcingaObjectGroup return $this; } - protected function notifyResolvers() + protected function getMemberShipResolver() { - $resolver = $this->getHostGroupMembershipResolver(); - $resolver->addGroup($this); - $resolver->refreshDb(); - - return $this; + return $this->getHostGroupMembershipResolver(); } } diff --git a/library/Director/Objects/IcingaObjectGroup.php b/library/Director/Objects/IcingaObjectGroup.php index bade094f..4ee363bc 100644 --- a/library/Director/Objects/IcingaObjectGroup.php +++ b/library/Director/Objects/IcingaObjectGroup.php @@ -31,4 +31,35 @@ abstract class IcingaObjectGroup extends IcingaObject implements ExportInterface { return true; } + + protected function memberShipShouldBeRefreshed(): bool + { + if ($this->hasBeenLoadedFromDb()) { + if (!array_key_exists('assign_filter', $this->getModifiedProperties())) { + return false; + } + } else { + if ($this->get('assign_filter') === null) { + return false; + } + } + + return true; + } + + protected function notifyResolvers() + { + if ($this->memberShipShouldBeRefreshed()) { + $resolver = $this->getMemberShipResolver(); + $resolver->addGroup($this); + $resolver->refreshDb(); + } + + return $this; + } + + protected function getMemberShipResolver() + { + return null; + } } diff --git a/library/Director/Objects/IcingaServiceGroup.php b/library/Director/Objects/IcingaServiceGroup.php index ae43ff32..92fb1cb0 100644 --- a/library/Director/Objects/IcingaServiceGroup.php +++ b/library/Director/Objects/IcingaServiceGroup.php @@ -31,12 +31,8 @@ class IcingaServiceGroup extends IcingaObjectGroup return $this; } - protected function notifyResolvers() + protected function getMemberShipResolver() { - $resolver = $this->getServiceGroupMembershipResolver(); - $resolver->addGroup($this); - $resolver->refreshDb(); - - return $this; + return $this->getServiceGroupMembershipResolver(); } }