From 251a82a754d2a1166beb776515b587d58d0a29a8 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Tue, 11 Feb 2025 15:47:17 +0100 Subject: [PATCH] [WIP] convert common_qualifiers to a compute stored --- runbot/models/build_error.py | 23 ++++++++++++----------- runbot/tests/test_build_error.py | 2 -- runbot/views/build_error_views.xml | 3 --- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/runbot/models/build_error.py b/runbot/models/build_error.py index e0eab0c86..af6f38220 100644 --- a/runbot/models/build_error.py +++ b/runbot/models/build_error.py @@ -103,7 +103,7 @@ class BuildError(models.Model): tags_min_version_id = fields.Many2one('runbot.version', 'Tags Min version', help="Minimal version where the test tags will be applied.") tags_max_version_id = fields.Many2one('runbot.version', 'Tags Max version', help="Maximal version where the test tags will be applied.") - common_qualifiers = JsonDictField('Selection Qualifiers', help="Minimal qualifiers in common needed to link error content.") + common_qualifiers = JsonDictField('Selection Qualifiers', compute='_compute_common_qualifiers', store=True, help="Minimal qualifiers in common needed to link error content.") similar_ids = fields.One2many('runbot.build.error', compute='_compute_similar_ids', string="Similar Errors", help="Similar Errors based on common qualifiers") # Build error related data @@ -152,6 +152,17 @@ def _compute_random(self): for record in self: record.random = any(error.random for error in record.error_content_ids) + @api.depends('error_content_ids.qualifiers') + def _compute_common_qualifiers(self): + for record in self: + qualifiers = defaultdict(set) + key_count = defaultdict(int) + for content in record.error_content_ids: + for key, value in content.qualifiers.dict.items(): + qualifiers[key].add(value) + key_count[key] += 1 + record.common_qualifiers = {k: v.pop() for k, v in qualifiers.items() if len(v) == 1 and key_count[k] == len(record.error_content_ids)} + @api.depends('common_qualifiers') def _compute_similar_ids(self): for record in self: @@ -262,16 +273,6 @@ def action_view_errors(self): 'target': 'current', } - def action_infer_qualifiers(self): - for record in self: - qualifiers = defaultdict(set) - key_count = defaultdict(int) - for content in record.error_content_ids: - for key, value in content.qualifiers.dict.items(): - qualifiers[key].add(value) - key_count[key] += 1 - record.common_qualifiers = {k: v.pop() for k, v in qualifiers.items() if len(v) == 1 and key_count[k] == len(record.error_content_ids)} - def action_show_qualified_contents(self): similar_content_ids = [] for record in self: diff --git a/runbot/tests/test_build_error.py b/runbot/tests/test_build_error.py index 10cc3436f..da3976b7d 100644 --- a/runbot/tests/test_build_error.py +++ b/runbot/tests/test_build_error.py @@ -570,8 +570,6 @@ def test_build_error_qualifers(self): main_error._merge(error_contents[1].error_id) self.assertEqual(len(main_error.error_content_ids), 2) - self.assertFalse(main_error.common_qualifiers) - main_error.action_infer_qualifiers() self.assertEqual(main_error.common_qualifiers.dict, expected_common_qualifiers) self.env.flush_all() self.assertEqual(len(main_error.similar_ids), 1) diff --git a/runbot/views/build_error_views.xml b/runbot/views/build_error_views.xml index 4c97d0485..f72875895 100644 --- a/runbot/views/build_error_views.xml +++ b/runbot/views/build_error_views.xml @@ -84,9 +84,6 @@
-