From 9d5b31fe1854f20be0e5892f5a661308194e340f Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Tue, 26 Nov 2024 15:40:16 +0100 Subject: [PATCH] [IMP] runbot: add a deduplicate server action Duplicate error content should not happens ... but it does. With this commit, a server actions allows to relink error contents and thus removes error contents having the same fingerprint. --- runbot/data/error_link.xml | 10 ++++++++++ runbot/models/build_error.py | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/runbot/data/error_link.xml b/runbot/data/error_link.xml index 97ec121e..155de13b 100644 --- a/runbot/data/error_link.xml +++ b/runbot/data/error_link.xml @@ -39,4 +39,14 @@ records.action_assign() + + Deduplicate Error Contents + + + ir.actions.server + code + + records.action_deduplicate() + + diff --git a/runbot/models/build_error.py b/runbot/models/build_error.py index 2c3db5ad..060acdff 100644 --- a/runbot/models/build_error.py +++ b/runbot/models/build_error.py @@ -486,6 +486,11 @@ class BuildErrorContent(models.Model): if not error.error_content_ids: base_error._merge(error) + def _get_duplicates(self): + """ returns a list of lists of duplicates""" + domain = [('id', 'in', self.ids)] if self else [] + return [r['id_arr'] for r in self.env['runbot.build.error.content'].read_group(domain, ['id_count:count(id)', 'id_arr:array_agg(id)', 'fingerprint'], ['fingerprint']) if r['id_count'] >1] + #################### # Actions #################### @@ -521,8 +526,13 @@ class BuildErrorContent(models.Model): for errors_content_to_merge in to_merge: errors_content_to_merge._relink() + def action_deduplicate(self): + rg = self._get_duplicates() + for ids_list in rg: + self.env['runbot.build.error.content'].browse(ids_list)._relink() + def action_find_duplicates(self): - rg = [r['id_arr'] for r in self.env['runbot.build.error.content'].read_group([], ['id_count:count(id)', 'id_arr:array_agg(id)', 'fingerprint'], ['fingerprint']) if r['id_count'] >1] + rg = self._get_duplicates() duplicate_ids = [] for ids_lists in rg: duplicate_ids += ids_lists