summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2019-03-27 13:38:46 +0000
committerAaron Bohy <aab@odoo.com>2019-04-02 11:57:00 +0000
commitca19b17fd3e09d2f4e53208542f4356d3a6ee25a (patch)
tree63b092ff0681647cfeba79db64bca051ca45ed0c /addons/web/static/src/js/views
parentd0164d834bb18f37f15a129e911f7d8e1c54b7c3 (diff)
[IMP] web: fetch records alongside read_group
This rev. adds params to the 'web_read_group' method, allowing to search_read records inside each groups in a single RPC, instead of doing a 'web_read_group' RPC followed by n 'search_read' RPCs, where n is the number of opened groups. Part of task 1915702
Diffstat (limited to 'addons/web/static/src/js/views')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js46
-rw-r--r--addons/web/static/src/js/views/list/list_model.js6
2 files changed, 36 insertions, 16 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index d07ec61abdd..804e6d6d1c9 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -4247,6 +4247,7 @@ var BasicModel = AbstractModel.extend({
*/
_readGroup: function (list, options) {
var self = this;
+ options = options || {};
var groupByField = list.groupedBy[0];
var rawGroupBy = groupByField.split(':')[0];
var fields = _.uniq(list.getFieldNames().concat(rawGroupBy));
@@ -4254,6 +4255,7 @@ var BasicModel = AbstractModel.extend({
return order.name === rawGroupBy || list.fields[order.name].group_operator !== undefined;
});
var openGroupsLimit = list.groupsLimit || self.OPEN_GROUP_LIMIT;
+ var expand = list.openGroupByDefault && options.fetchRecordsWithGroups;
return this._rpc({
model: list.model,
method: 'web_read_group',
@@ -4265,6 +4267,9 @@ var BasicModel = AbstractModel.extend({
offset: list.groupsOffset,
orderBy: orderedBy,
lazy: true,
+ expand: expand,
+ expand_limit: expand ? list.limit : null,
+ expand_orderby: expand ? list.orderedBy : null,
})
.then(function (result) {
var groups = result.groups;
@@ -4318,7 +4323,7 @@ var BasicModel = AbstractModel.extend({
delete self.localData[newGroup.id];
// restore the internal state of the group
var updatedProps = _.pick(oldGroup, 'isOpen', 'offset', 'id');
- if (options && options.onlyGroups || oldGroup.isOpen && newGroup.groupedBy.length) {
+ if (options.onlyGroups || oldGroup.isOpen && newGroup.groupedBy.length) {
// If the group is opened and contains subgroups,
// also keep its data to keep internal state of
// sub-groups
@@ -4343,11 +4348,16 @@ var BasicModel = AbstractModel.extend({
list.count += newGroup.count;
if (newGroup.isOpen && newGroup.count > 0) {
openGroupCount++;
+ if (group.__data) {
+ // bypass the search_read when the group's records have been obtained
+ // by the call to 'web_read_group' (see @_searchReadUngroupedList)
+ newGroup.__data = group.__data;
+ }
options = _.defaults({enableRelationalFetch: false}, options);
defs.push(self._load(newGroup, options));
}
});
- if (options && options.keepEmptyGroups) {
+ if (options.keepEmptyGroups) {
// Find the groups that were available in a previous
// readGroup but are not there anymore.
// Note that these groups are put after existing groups so
@@ -4363,7 +4373,7 @@ var BasicModel = AbstractModel.extend({
}
return Promise.all(defs).then(function (groups) {
- if (!options || !options.onlyGroups) {
+ if (!options.onlyGroups) {
// generate the res_ids of the main list, being the concatenation
// of the fetched res_ids in each group
list.res_ids = _.flatten(_.map(groups, function (group) {
@@ -4552,17 +4562,25 @@ var BasicModel = AbstractModel.extend({
_searchReadUngroupedList: function (list) {
var self = this;
var fieldNames = list.getFieldNames();
- return this._rpc({
- route: '/web/dataset/search_read',
- model: list.model,
- fields: fieldNames,
- context: list.getContext(),
- domain: list.domain || [],
- limit: list.limit,
- offset: list.loadMoreOffset + list.offset,
- orderBy: list.orderedBy,
- })
- .then(function (result) {
+ var prom;
+ if (list.__data) {
+ // the data have already been fetched (alonside the groups by the
+ // call to 'web_read_group'), so we can bypass the search_read
+ prom = Promise.resolve(list.__data);
+ } else {
+ prom = this._rpc({
+ route: '/web/dataset/search_read',
+ model: list.model,
+ fields: fieldNames,
+ context: list.getContext(),
+ domain: list.domain || [],
+ limit: list.limit,
+ offset: list.loadMoreOffset + list.offset,
+ orderBy: list.orderedBy,
+ });
+ }
+ return prom.then(function (result) {
+ delete list.__data;
list.count = result.length;
var ids = _.pluck(result.records, 'id');
var data = _.map(result.records, function (record) {
diff --git a/addons/web/static/src/js/views/list/list_model.js b/addons/web/static/src/js/views/list/list_model.js
index 73c2d86864d..41178498c96 100644
--- a/addons/web/static/src/js/views/list/list_model.js
+++ b/addons/web/static/src/js/views/list/list_model.js
@@ -89,9 +89,11 @@ odoo.define('web.ListModel', function (require) {
* @override
* @private
*/
- _readGroup: function (list) {
+ _readGroup: function (list, options) {
var self = this;
- return this._super.apply(this, arguments).then(function (result) {
+ options = options || {};
+ options.fetchRecordsWithGroups = true;
+ return this._super(list, options).then(function (result) {
var prom;
if (!list.parentID) {
// groupbys buttons are only displayed on the first level of