Reduce mapping storage overhead

This commit is contained in:
Rashid Khan 2013-12-09 12:57:11 -07:00
parent 8a5a974878
commit 85bfed67de

View File

@ -13,23 +13,22 @@ function (angular, _, config) {
var self = this; var self = this;
this.list = ['_type']; this.list = ['_type'];
this.mapping = {}; this.indices = [];
this.fullMapping = {};
// Stop tracking the full mapping, too expensive, instead we only remember the index names
// we've already seen.
//
$rootScope.$watch(function(){return dashboard.indices;},function(n) { $rootScope.$watch(function(){return dashboard.indices;},function(n) {
if(!_.isUndefined(n) && n.length && dashboard.current.index.warm_fields) { if(!_.isUndefined(n) && n.length && dashboard.current.index.warm_fields) {
// Only get the mapping for indices we don't know it for // Only get the mapping for indices we don't know it for
var indices = _.difference(n,_.keys(self.fullMapping)); var indices = _.difference(n,_.keys(self.indices));
// Only get the mapping if there are new indices // Only get the mapping if there are new indices
if(indices.length > 0) { if(indices.length > 0) {
self.map(indices).then(function(result) { self.map(indices).then(function(result) {
self.fullMapping = _.extend(self.fullMapping,result); self.indices = _.union(self.indices,_.keys(result));
self.list = mapFields(self.fullMapping); self.list = mapFields(result);
}); });
// Otherwise just use the cached mapping // Otherwise just use the cached mapping
} else {
// This is inefficient, should not need to reprocess?
self.list = mapFields(_.pick(self.fullMapping,n));
} }
} }
}); });
@ -37,8 +36,8 @@ function (angular, _, config) {
var mapFields = function (m) { var mapFields = function (m) {
var fields = []; var fields = [];
_.each(m, function(types) { _.each(m, function(types) {
_.each(types, function(v) { _.each(types, function(type) {
fields = _.without(_.union(fields,_.keys(v)),'_all','_source'); fields = _.without(_.union(fields,_.keys(type)),'_all','_source');
}); });
}); });
return fields; return fields;