From e9d29c63bafe9322856ed17cc02e8ad848003701 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Sun, 31 Jan 2016 15:14:48 +0300 Subject: [PATCH] Wrap cache refresh() method to call it once. --- plugins/datasource-zabbix/zabbixCache.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/datasource-zabbix/zabbixCache.js b/plugins/datasource-zabbix/zabbixCache.js index dc68ff4..1fe6e31 100644 --- a/plugins/datasource-zabbix/zabbixCache.js +++ b/plugins/datasource-zabbix/zabbixCache.js @@ -24,11 +24,31 @@ function (angular, _, utils) { // Check is a service initialized or not this._initialized = undefined; + + this.refreshPromise = false; } var p = ZabbixCachingProxy.prototype; - p.refresh = function () { + /** + * Wrap _refresh() method to call it once. + */ + p.refresh = function() { + var self = this; + var deferred = $q.defer(); + if (!self.refreshPromise) { + self.refreshPromise = deferred.promise; + self._refresh().then(function() { + deferred.resolve(); + self.refreshPromise = null; + }); + } else { + return self.refreshPromise; + } + return deferred.promise; + }; + + p._refresh = function() { var self = this; var promises = [ this.zabbixAPI.getGroups(),