[IMP] performance improvement: write a custom isEqual function to use instead of _.isEqual to make the code faster in graph view (isEqual was determined guilty of being slow by profiling on a large view) (addon web_graph)
bzr revid: ged@openerp.com-20140409145735-m21t2fzmaepr1hsa
This commit is contained in:
parent
281c19a751
commit
f966931b87
|
@ -281,7 +281,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
var row_value = (prefix || []).concat(data_pt.attributes.value.slice(0,index));
|
||||
var col_value = data_pt.attributes.value.slice(index);
|
||||
|
||||
if (expand && !_.find(col_headers, function (hdr) {return _.isEqual(col_value, hdr.path);})) {
|
||||
if (expand && !_.find(col_headers, function (hdr) {return self.isEqual(col_value, hdr.path);})) {
|
||||
return;
|
||||
}
|
||||
var row = self.find_or_create_header(row_headers, row_value, data_pt);
|
||||
|
@ -311,8 +311,9 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
},
|
||||
|
||||
find_or_create_header: function (headers, path, data_pt) {
|
||||
var self = this;
|
||||
var hdr = _.find(headers, function (header) {
|
||||
return _.isEqual(path, header.path);
|
||||
return self.isEqual(path, header.path);
|
||||
});
|
||||
if (hdr) {
|
||||
return hdr;
|
||||
|
@ -328,7 +329,7 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
title: _t(_.last(path))
|
||||
});
|
||||
var parent = _.find(headers, function (header) {
|
||||
return _.isEqual(header.path, _.initial(path, 1));
|
||||
return self.isEqual(header.path, _.initial(path, 1));
|
||||
});
|
||||
|
||||
var previous = parent.children.length ? _.last(parent.children) : parent;
|
||||
|
@ -360,10 +361,11 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
|
||||
// set the 'expanded' status of new_headers more or less like root.headers, with root as root
|
||||
set_headers: function(new_headers, root) {
|
||||
var self = this;
|
||||
if (root.headers) {
|
||||
_.each(root.headers, function (header) {
|
||||
var corresponding_header = _.find(new_headers, function (h) {
|
||||
return _.isEqual(h.path, header.path);
|
||||
return self.isEqual(h.path, header.path);
|
||||
});
|
||||
if (corresponding_header && header.expanded) {
|
||||
corresponding_header.expanded = true;
|
||||
|
@ -431,6 +433,16 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend({
|
|||
return field.split(':')[0];
|
||||
},
|
||||
|
||||
isEqual: function (path1, path2) {
|
||||
if (path1.length !== path2.length) { return false; }
|
||||
for (var i = 0; i < path1.length; i++) {
|
||||
if (path1[i] !== path2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue