From b03164db9027875494d94a72211d6343b1d056c0 Mon Sep 17 00:00:00 2001 From: Hpar Date: Tue, 30 May 2017 12:31:05 +0200 Subject: [PATCH] [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 --- web_m2x_options/static/src/js/form.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/web_m2x_options/static/src/js/form.js b/web_m2x_options/static/src/js/form.js index 1d0d5502..ad49ce92 100644 --- a/web_m2x_options/static/src/js/form.js +++ b/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,