Fixed calculating api request hash.
This commit is contained in:
@@ -41,6 +41,7 @@ angular.module('grafana.services').factory('ZabbixCachingProxy', function($q, $i
|
|||||||
this.getHistory = callHistoryOnce(_.bind(this.zabbixAPI.getHistory, this.zabbixAPI),
|
this.getHistory = callHistoryOnce(_.bind(this.zabbixAPI.getHistory, this.zabbixAPI),
|
||||||
this.historyPromises);
|
this.historyPromises);
|
||||||
|
|
||||||
|
// Don't run duplicated requests
|
||||||
this.groupPromises = {};
|
this.groupPromises = {};
|
||||||
this.getGroupsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getGroups, this.zabbixAPI),
|
this.getGroupsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getGroups, this.zabbixAPI),
|
||||||
this.groupPromises);
|
this.groupPromises);
|
||||||
@@ -156,10 +157,7 @@ angular.module('grafana.services').factory('ZabbixCachingProxy', function($q, $i
|
|||||||
|
|
||||||
function callAPIRequestOnce(func, promiseKeeper) {
|
function callAPIRequestOnce(func, promiseKeeper) {
|
||||||
return function() {
|
return function() {
|
||||||
var itemids = _.map(arguments[0], 'itemid');
|
var hash = getAPIRequestHash(arguments);
|
||||||
var stamp = itemids.join() + arguments[1] + arguments[2];
|
|
||||||
var hash = stamp.getHash();
|
|
||||||
|
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
if (!promiseKeeper[hash]) {
|
if (!promiseKeeper[hash]) {
|
||||||
promiseKeeper[hash] = deferred.promise;
|
promiseKeeper[hash] = deferred.promise;
|
||||||
@@ -213,6 +211,17 @@ angular.module('grafana.services').factory('ZabbixCachingProxy', function($q, $i
|
|||||||
return ZabbixCachingProxy;
|
return ZabbixCachingProxy;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getAPIRequestHash(args) {
|
||||||
|
var requestStamp = _.map(args, arg => {
|
||||||
|
if (arg === undefined) {
|
||||||
|
return 'undefined';
|
||||||
|
} else {
|
||||||
|
return arg.toString();
|
||||||
|
}
|
||||||
|
}).join();
|
||||||
|
return requestStamp.getHash();
|
||||||
|
}
|
||||||
|
|
||||||
String.prototype.getHash = function() {
|
String.prototype.getHash = function() {
|
||||||
var hash = 0, i, chr, len;
|
var hash = 0, i, chr, len;
|
||||||
if (this.length === 0) {
|
if (this.length === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user