Module: check_mk
Branch: master
Commit: 84f45d44f2731632737bb6b6e94406183636aadb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=84f45d44f27316…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Dec 12 10:39:02 2018 +0100
WK6698: The 'Activates button' no longer cause performance issues
Change-Id: Id2ebc2eab2cc4a72af79670cb87901b4d29965e9
---
.werks/6698 | 13 +++++++++++++
cmk/gui/plugins/wato/utils/context_buttons.py | 13 ++++---------
cmk/gui/wato/pages/host_rename.py | 2 +-
cmk/gui/watolib.py | 16 ++++++++++++++++
4 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/.werks/6698 b/.werks/6698
new file mode 100644
index 0000000..0f6b19a
--- /dev/null
+++ b/.werks/6698
@@ -0,0 +1,13 @@
+Title: The "Activates button" no longer cause performance issues when there are
hundreds of open changes
+Level: 1
+Component: wato
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1544530074
+
+If there are more than 10 changes in the WATO configuration the button simply states
<tt>10+ changes</tt>,
+instead of digging through the whole configuration till it gets the exact number.
+
diff --git a/cmk/gui/plugins/wato/utils/context_buttons.py
b/cmk/gui/plugins/wato/utils/context_buttons.py
index 02f0f83..a4edc8d 100644
--- a/cmk/gui/plugins/wato/utils/context_buttons.py
+++ b/cmk/gui/plugins/wato/utils/context_buttons.py
@@ -38,20 +38,15 @@ def home_button():
def changelog_button():
- num_pending = watolib.get_number_of_pending_changes()
- if num_pending >= 1:
+ pending_info = watolib.get_pending_changes_info()
+ if pending_info:
hot = True
icon = "wato_changes"
-
- if num_pending == 1:
- buttontext = _("1 change")
- else:
- buttontext = _("%d changes") % num_pending
-
+ buttontext = pending_info
else:
- buttontext = _("No changes")
hot = False
icon = "wato_nochanges"
+ buttontext = _("No changes")
html.context_button(buttontext, watolib.folder_preserving_link([("mode",
"changelog")]), icon,
hot)
diff --git a/cmk/gui/wato/pages/host_rename.py b/cmk/gui/wato/pages/host_rename.py
index ae44da8..69c367f 100644
--- a/cmk/gui/wato/pages/host_rename.py
+++ b/cmk/gui/wato/pages/host_rename.py
@@ -381,7 +381,7 @@ class ModeRenameHost(WatoMode):
_("Last result"), host_renaming_job.detail_url(),
"background_job_details")
def action(self):
- if watolib.get_number_of_pending_changes():
+ if watolib.get_pending_changes_info():
raise MKUserError("newname",
_("You cannot rename a host while you have pending
changes."))
diff --git a/cmk/gui/watolib.py b/cmk/gui/watolib.py
index 0cfb9a3..e27241a 100644
--- a/cmk/gui/watolib.py
+++ b/cmk/gui/watolib.py
@@ -558,6 +558,11 @@ def add_service_change(host, action_name, text, need_sync=False):
add_change(action_name, text, obj=host, sites=[host.site_id()], need_sync=need_sync)
+def get_pending_changes_info():
+ changes = ActivateChanges()
+ return changes.get_changes_estimate()
+
+
def get_number_of_pending_changes():
changes = ActivateChanges()
changes.load()
@@ -5043,6 +5048,17 @@ class ActivateChanges(object):
self._changes = sorted(changes.items(), key=lambda k_v:
k_v[1]["time"])
+ def get_changes_estimate(self):
+ changes_counter = 0
+ for site_id in self.activation_site_ids():
+ changes_counter += len(self._load_site_changes(site_id))
+ if changes_counter > 10:
+ return _("10+ changes")
+ if changes_counter == 1:
+ return _("1 change")
+ elif changes_counter > 1:
+ return _("%d changes") % changes_counter
+
def grouped_changes(self):
return self._changes