[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.
This commit is contained in:
@@ -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, {});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -16,6 +16,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,10 +74,28 @@ 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
|
||||
*/
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user