[FIX] web: fix performance issue with read_progress_bar

This PR fixes some miscellaneous issues:
- performance issue in read_progress_bar
- performance issue in activity view
- crash in ungrouped kanban view with progress bar

closes odoo/odoo#28715
This commit is contained in:
Robot Odoo
2018-11-15 17:25:30 +01:00
committed by GitHub
4 changed files with 41 additions and 6 deletions
+4 -3
View File
@@ -422,8 +422,10 @@ class MailActivity(models.Model):
@api.model
def get_activity_data(self, res_model, domain):
res = self.env[res_model].search(domain)
activity_domain = [('res_id', 'in', res.ids), ('res_model', '=', res_model)]
activity_domain = [('res_model', '=', res_model)]
if domain:
res = self.env[res_model].search(domain)
activity_domain.append(('res_id', 'in', res.ids))
grouped_activities = self.env['mail.activity'].read_group(
activity_domain,
['res_id', 'activity_type_id', 'res_name:max(res_name)', 'ids:array_agg(id)', 'date_deadline:min(date_deadline)'],
@@ -443,7 +445,6 @@ class MailActivity(models.Model):
state = self._compute_state_from_date(group['date_deadline'], self.user_id.sudo().tz)
activity_data[res_id][activity_type_id] = {
'count': group['__count'],
'domain': group['__domain'],
'ids': group['ids'],
'state': state,
'o_closest_deadline': group['date_deadline'],
+5 -2
View File
@@ -40,11 +40,14 @@ class Base(models.AbstractModel):
records_values = self.search_read(domain or [], [progress_bar['field'], group_by])
data = {}
field_type = self._fields[group_by].type
if field_type == 'selection':
selection_labels = dict(self.fields_get()[group_by]['selection'])
for record_values in records_values:
group_by_value = record_values[group_by]
# Again, imitating what _read_group_format_result and _read_group_prepare_data do
field_type = self._fields[group_by].type
if group_by_value and field_type in ['date', 'datetime']:
locale = self._context.get('lang') or 'en_US'
group_by_value = fields.Datetime.to_datetime(group_by_value)
@@ -61,7 +64,7 @@ class Base(models.AbstractModel):
locale=locale)
if field_type == 'selection':
group_by_value = dict(self.fields_get()[group_by]['selection'])[group_by_value]
group_by_value = selection_labels[group_by_value]
if type(group_by_value) == tuple:
group_by_value = group_by_value[1] # FIXME should use technical value (0)
@@ -305,7 +305,7 @@ var KanbanModel = BasicModel.extend({
* @override
*/
_load: function (dataPoint, options) {
if (dataPoint.progressBar) {
if (dataPoint.groupedBy.length && dataPoint.progressBar) {
return this._readProgressBarGroup(dataPoint, options);
}
return this._super.apply(this, arguments);
@@ -4232,6 +4232,37 @@ QUnit.module('Views', {
kanban.destroy();
});
QUnit.test('column progressbars should not crash in non grouped views', function (assert) {
assert.expect(3);
var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch:
'<kanban>' +
'<field name="bar"/>' +
'<field name="int_field"/>' +
'<progressbar field="foo" colors=\'{"yop": "success", "gnap": "warning", "blip": "danger"}\' sum_field="int_field"/>' +
'<templates><t t-name="kanban-box">' +
'<div>' +
'<field name="name"/>' +
'</div>' +
'</t></templates>' +
'</kanban>',
mockRPC: function (route, args) {
assert.step(route)
return this._super(route, args);
},
});
assert.strictEqual(kanban.$('.o_kanban_record').text(), 'namenamenamename',
"should have renderer 4 records");
assert.verifySteps(['/web/dataset/search_read'], "no read on progress bar data is done");
kanban.destroy();
});
QUnit.test('column progressbars: creating a new column should create a new progressbar', function (assert) {
assert.expect(1);