Browse Source

[IMP] web_m2x_options: Perf issue https://github.com/OCA/web/issues/615

* fix unecessary calls

Do check_access_rights and disable_quick_create calls only once per field.
pull/952/head
jesusVMayor 8 years ago
committed by Pedro M. Baeza
parent
commit
12be6d2b4b
  1. 25
      web_m2x_options/static/src/js/form.js

25
web_m2x_options/static/src/js/form.js

@ -111,7 +111,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
if (_.isUndefined(this.view)) if (_.isUndefined(this.view))
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) { if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) {
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']);
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit'], 10);
} }
if (typeof this.options.limit === 'number') { if (typeof this.options.limit === 'number') {
@ -134,13 +134,14 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
'ilike', this.limit + 1, 'ilike', this.limit + 1,
self.build_context())); self.build_context()));
var create_rights;
if (!(self.options && (self.is_option_set(self.options.create) || self.is_option_set(self.options.create_edit)))) { if (!(self.options && (self.is_option_set(self.options.create) || self.is_option_set(self.options.create_edit)))) {
create_rights = new Model(this.field.relation).call(
this.create_rights = this.create_rights || (function(){
return new Model(self.field.relation).call(
"check_access_rights", ["create", false]); "check_access_rights", ["create", false]);
})();
} }
$.when(search_result, create_rights).then(function (data, can_create) {
$.when(search_result, this.create_rights).then(function (data, can_create) {
self.can_create = can_create; // for ``.show_error_displayer()`` self.can_create = can_create; // for ``.show_error_displayer()``
self.last_search = data; self.last_search = data;
@ -200,7 +201,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
self._search_create_popup("search", data); self._search_create_popup("search", data);
}); });
}, },
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
}); });
} }
@ -225,7 +226,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
action: function () { action: function () {
self._quick_create(search_val); self._quick_create(search_val);
}, },
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
}); });
} }
} }
@ -244,7 +245,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
"form", undefined, "form", undefined,
self._create_context(search_val)); self._create_context(search_val));
}, },
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
}); });
} }
// Check if colors specified to wait for RPC // Check if colors specified to wait for RPC
@ -316,7 +317,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
// returned. // returned.
if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) { if (!_.isUndefined(this.view.ir_options['web_m2x_options.limit'])) {
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit']);
this.limit = parseInt(this.view.ir_options['web_m2x_options.limit'], 10);
} }
if (typeof this.options.limit === 'number') { if (typeof this.options.limit === 'number') {
@ -356,7 +357,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
self._search_create_popup("search", data); self._search_create_popup("search", data);
}); });
}, },
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
}); });
} }
// quick create // quick create
@ -375,7 +376,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
action: function() { action: function() {
self._quick_create(search_val); self._quick_create(search_val);
}, },
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
}); });
} }
} }
@ -393,7 +394,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
action: function() { action: function() {
self._search_create_popup("form", undefined, self._create_context(search_val)); self._search_create_popup("form", undefined, self._create_context(search_val));
}, },
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
classname: 'oe_m2o_dropdown_option o_m2o_dropdown_option'
}); });
} }
@ -406,7 +407,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
var open = (self.options && self.is_option_set(self.options.open)); var open = (self.options && self.is_option_set(self.options.open));
if(open){ if(open){
self.mutex.exec(function(){ self.mutex.exec(function(){
var id = parseInt($(ev.currentTarget).data('id'));
var id = parseInt($(ev.currentTarget).data('id'), 10);
self.do_action({ self.do_action({
type: 'ir.actions.act_window', type: 'ir.actions.act_window',
res_model: self.field.relation, res_model: self.field.relation,

Loading…
Cancel
Save