Module: check_mk
Branch: master
Commit: 14d8dbca7bb2f68cb0c18adc1c45c7c46fe664d1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=14d8dbca7bb2f6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 28 14:28:37 2019 +0100
7331 FIX Fixed decreased performance in host / service views since 1.5.0p5
When using the HW/SW inventory the performance of views, especially in
distributed setups with slower responding sites, could be decreased
significantly because the GUI performed too many livestatus requests in the
background.
This was caused by werk #6594 which was added in 1.5.0p5.
CMK-1861
Change-Id: If4c7b04a09b516706dab20968d46bdfbd7e4c4d5
---
.werks/7331 | 16 ++++++++++++++++
cmk/gui/plugins/views/inventory.py | 24 ++++++++++++++++++------
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/.werks/7331 b/.werks/7331
new file mode 100644
index 0000000..f29d031
--- /dev/null
+++ b/.werks/7331
@@ -0,0 +1,16 @@
+Title: Fixed decreased performance in host / service views since 1.5.0p5
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1553774075
+
+When using the HW/SW inventory the performance of views, especially in
+distributed setups with slower responding sites, could be decreased
+significantly because the GUI performed too many livestatus requests in the
+background.
+
+This was caused by werk #6594 which was added in 1.5.0p5.
diff --git a/cmk/gui/plugins/views/inventory.py b/cmk/gui/plugins/views/inventory.py
index 5bd54e9..24edb67 100644
--- a/cmk/gui/plugins/views/inventory.py
+++ b/cmk/gui/plugins/views/inventory.py
@@ -36,7 +36,7 @@ import cmk.gui.sites as sites
import cmk.gui.utils as utils
import cmk.gui.inventory as inventory
from cmk.gui.i18n import _
-from cmk.gui.globals import html
+from cmk.gui.globals import html, current_app
from cmk.gui.htmllib import HTML
from cmk.gui.valuespec import Checkbox, Hostname
from cmk.gui.exceptions import MKUserError
@@ -1696,11 +1696,7 @@ def _create_view_enabled_check_func(invpath, is_history=False):
# FIXME In order to decide whether this view is enabled
# do we really need to load the whole tree?
- if is_history:
- struct_tree = inventory.load_filtered_inventory_tree(hostname)
- else:
- row = inventory.get_status_data_via_livestatus(context.get("site"),
hostname)
- struct_tree = inventory.load_filtered_and_merged_tree(row)
+ struct_tree = _get_struct_tree(is_history, hostname,
context.get("site"))
if not struct_tree:
return False
@@ -1720,6 +1716,22 @@ def _create_view_enabled_check_func(invpath, is_history=False):
return _check_view_enabled
+def _get_struct_tree(is_history, hostname, site_id):
+ struct_tree_cache = current_app.g.setdefault("struct_tree_cache", {})
+ cache_id = (is_history, hostname, site_id)
+ if cache_id in struct_tree_cache:
+ return struct_tree_cache[cache_id]
+
+ if is_history:
+ struct_tree = inventory.load_filtered_inventory_tree(hostname)
+ else:
+ row = inventory.get_status_data_via_livestatus(site_id, hostname)
+ struct_tree = inventory.load_filtered_and_merged_tree(row)
+
+ struct_tree_cache[cache_id] = struct_tree
+ return struct_tree
+
+
# Now declare Multisite views for a couple of embedded tables
declare_invtable_view(
"invswpac",