summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-07-31 11:50:56 +0000
committerJulien Mougenot <jum@odoo.com>2020-08-04 12:44:18 +0000
commitcc6a60bec935a42e19bac0bef5771dfcbad81f83 (patch)
treeea234a9eb85b55cd12cae650fc5782cbb30325d1 /addons/web
parent6e780b2e4f69cdee247afe4be964227a90b3d738 (diff)
[IMP] web: Optimize action model loading
The loading of the action model extensions have been split in this commit: - when calling load, a first promise is returned. It is meant to be resolved as soon as all the query informations are available. - a second promise returned by a new method "isReady" is resolved when all of the extension data have been fetched. This difference allow to not wait for server calls irrelevant for the query. By default "isReady" will always wait for a full load call, but this is meant to be overridden in case optimisations can be made.
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/static/src/js/views/abstract_controller.js1
-rw-r--r--addons/web/static/src/js/views/abstract_view.js11
-rw-r--r--addons/web/static/src/js/views/action_model.js52
3 files changed, 56 insertions, 8 deletions
diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js
index 5128fa6d9a8..2f819bff7a5 100644
--- a/addons/web/static/src/js/views/abstract_controller.js
+++ b/addons/web/static/src/js/views/abstract_controller.js
@@ -222,7 +222,6 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
reload: async function (params = {}) {
if (params.controllerState) {
this.importState(params.controllerState);
- await this.searchModel.load();
Object.assign(params, this.searchModel.get('query'));
}
return this.update(params, {});
diff --git a/addons/web/static/src/js/views/abstract_view.js b/addons/web/static/src/js/views/abstract_view.js
index 04b1b781848..129cb6817b3 100644
--- a/addons/web/static/src/js/views/abstract_view.js
+++ b/addons/web/static/src/js/views/abstract_view.js
@@ -306,13 +306,16 @@ var AbstractView = Factory.extend({
*/
getController: async function () {
const _super = this._super.bind(this);
- await this.controllerParams.searchModel.load();
- const query = this.controllerParams.searchModel.get('query');
- this._updateMVCParams(query);
+ const { searchModel } = this.controllerParams;
+ await searchModel.load();
+ this._updateMVCParams(searchModel.get("query"));
// get the parent of the model if it already exists, as _super will
// set the new controller as parent, which we don't want
const modelParent = this.model && this.model.getParent();
- const controller = await _super(...arguments);
+ const [controller] = await Promise.all([
+ _super(...arguments),
+ searchModel.isReady(),
+ ]);
if (modelParent) {
// if we already add a model, restore its parent
this.model.setParent(modelParent);
diff --git a/addons/web/static/src/js/views/action_model.js b/addons/web/static/src/js/views/action_model.js
index 382aa30531b..c3b69271a07 100644
--- a/addons/web/static/src/js/views/action_model.js
+++ b/addons/web/static/src/js/views/action_model.js
@@ -17,6 +17,29 @@ odoo.define("web/static/src/js/views/action_model.js", function (require) {
class ActionModelExtension extends Model.Extension {
//---------------------------------------------------------------------
+ // Public
+ //---------------------------------------------------------------------
+
+ /**
+ * Initiates the asynchronous tasks of the extension and returns a
+ * promise resolved as soon as all the informations necessary to build
+ * the search query are ready.
+ * @returns {Promise}
+ */
+ async callLoad() {
+ this.loadPromise = super.callLoad(...arguments);
+ await this.loadPromise;
+ }
+
+ /**
+ * Returns a promise resolved when the extension is completely ready.
+ * @returns {Promise}
+ */
+ async isReady() {
+ await this.loadPromise;
+ }
+
+ //---------------------------------------------------------------------
// Static
//---------------------------------------------------------------------
@@ -51,11 +74,29 @@ odoo.define("web/static/src/js/views/action_model.js", function (require) {
return super.get(...arguments);
}
+ /**
+ * Returns a promise resolved when all extensions are completely ready.
+ * @returns {Promise}
+ */
+ async isReady() {
+ await this._awaitExtensions();
+ }
+
//---------------------------------------------------------------------
// Private
//---------------------------------------------------------------------
/**
+ * @private
+ * @returns {Promise}
+ */
+ async _awaitExtensions() {
+ await Promise.all(this.extensions.flat().map(
+ (extension) => extension.isReady()
+ ));
+ }
+
+ /**
* @override
*/
__get(excluded, property) {
@@ -140,11 +181,16 @@ odoo.define("web/static/src/js/views/action_model.js", function (require) {
}
/**
+ * Overridden to trigger a "search" event as soon as the query data
+ * are ready.
* @override
*/
- _notifyComponents() {
- this.trigger("search", this.get("query"));
- super._notifyComponents(...arguments);
+ async _loadExtensions({ isInitialLoad }) {
+ await super._loadExtensions(...arguments);
+ if (!isInitialLoad) {
+ this.trigger("search", this.get("query"));
+ await this._awaitExtensions();
+ }
}
//---------------------------------------------------------------------