mysql-connector: deduplicate requests
This commit is contained in:
@@ -8,8 +8,9 @@ import _ from 'lodash';
|
||||
function ZabbixCachingProxyFactory() {
|
||||
|
||||
class ZabbixCachingProxy {
|
||||
constructor(zabbixAPI, cacheOptions) {
|
||||
constructor(zabbixAPI, zabbixDBConnector, cacheOptions) {
|
||||
this.zabbixAPI = zabbixAPI;
|
||||
this.dbConnector = zabbixDBConnector;
|
||||
this.cacheEnabled = cacheOptions.enabled;
|
||||
this.ttl = cacheOptions.ttl || 600000; // 10 minutes by default
|
||||
|
||||
@@ -31,6 +32,13 @@ function ZabbixCachingProxyFactory() {
|
||||
this.getHistory = callAPIRequestOnce(_.bind(this.zabbixAPI.getHistory, this.zabbixAPI),
|
||||
this.historyPromises, getHistoryRequestHash);
|
||||
|
||||
if (this.dbConnector) {
|
||||
this.getHistoryDB = callAPIRequestOnce(_.bind(this.dbConnector.getHistory, this.dbConnector),
|
||||
this.historyPromises, getDBQueryHash);
|
||||
this.getTrendsDB = callAPIRequestOnce(_.bind(this.dbConnector.getTrends, this.dbConnector),
|
||||
this.historyPromises, getDBQueryHash);
|
||||
}
|
||||
|
||||
// Don't run duplicated requests
|
||||
this.groupPromises = {};
|
||||
this.getGroupsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getGroups, this.zabbixAPI),
|
||||
@@ -195,6 +203,14 @@ function getHistoryRequestHash(args) {
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
function getDBQueryHash(args) {
|
||||
let itemids = _.map(args[0], 'itemid');
|
||||
let consolidateBy = args[3].consolidateBy;
|
||||
let intervalMs = args[3].intervalMs;
|
||||
let stamp = itemids.join() + args[1] + args[2] + consolidateBy + intervalMs;
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
String.prototype.getHash = function() {
|
||||
var hash = 0, i, chr, len;
|
||||
if (this.length !== 0) {
|
||||
|
||||
Reference in New Issue
Block a user