Browse Source

[IMP] web_m2x_options: Perf issue #615 (#641)

* fix unecessary calls

Do check_access_rights and disable_quick_create calls only once per field.

Closes #615
pull/247/merge
Hpar 7 years ago
committed by Pedro M. Baeza
parent
commit
b03164db90
  1. 27
      web_m2x_options/static/src/js/form.js

27
web_m2x_options/static/src/js/form.js

@ -70,7 +70,7 @@ openerp.web_m2x_options = function (instance) {
if (_.isUndefined(this.view))
return this._super.apply(this, arguments);
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') {
@ -98,24 +98,25 @@ openerp.web_m2x_options = function (instance) {
'ilike', this.limit + 1,
self.build_context()));
var create_rights;
if (!(self.options && (self.options.no_create || self.options.no_create_edit))) {
// check quick create options
var target_model = this.field.relation
create_rights = new instance.web.Model('ir.model').
this.create_rights = this.create_rights || (function () {
//call check_access_rights once
var target_model = self.field.relation
if (self.options.no_create || self.options.no_create_edit)
return $.when(false);
return new instance.web.Model('ir.model').
query(['disable_quick_create']).
filter([['model', '=', target_model]]).
first().
then(function(result){
if(result.disable_quick_create)
return $.when(false);
else
return new instance.web.Model(target_model).call(
"check_access_rights", ["create", false]);
return new instance.web.Model(target_model).call(
"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.last_search = data;
@ -291,7 +292,7 @@ openerp.web_m2x_options = function (instance) {
// returned.
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') {
@ -401,7 +402,7 @@ openerp.web_m2x_options = function (instance) {
.css('cursor', 'pointer')
.click(function(e)
{
var id = parseInt(jQuery(this).attr('data-id'));
var id = parseInt(jQuery(this).attr('data-id'), 10);
self.do_action({
type: 'ir.actions.act_window',
res_model: self.field.relation,

Loading…
Cancel
Save