From c4d0b5697216225b81366fe85a07234c945bc5d2 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 16 Mar 2022 09:20:23 +0100 Subject: [PATCH] [FIX] runbot: dont duplicate export Even if it isn't really problematic, avoiding to duplicate exports will make the table slighly smaller, especially when considering running builds. --- runbot/models/build.py | 4 ++-- runbot/models/commit.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/runbot/models/build.py b/runbot/models/build.py index 2479396f4..f4b0b09b2 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -329,6 +329,8 @@ def write(self, values): build_by_old_values = defaultdict(lambda: self.env['runbot.build']) for record in self: build_by_old_values[record.local_state] += record + if values['local_state'] == 'done': + self.env['runbot.commit.export'].search([('build_id', 'in', self.ids)]).unlink() local_result = values.get('local_result') for build in self: if local_result and local_result != self._get_worst_result([build.local_result, local_result]): # dont write ok on a warn/error build @@ -729,8 +731,6 @@ def _schedule(self): build._github_status() build._run_job() - if build.local_state == 'done': - self.env['runbot.commit.export'].search([('build_id', '=', build.id)]).unlink() def _run_job(self): # run job diff --git a/runbot/models/commit.py b/runbot/models/commit.py index cb12b3784..e2e3d0d43 100644 --- a/runbot/models/commit.py +++ b/runbot/models/commit.py @@ -56,7 +56,8 @@ def export(self, build): """Export a git repo into a sources""" # TODO add automated tests self.ensure_one() - self.env['runbot.commit.export'].create({'commit_id': self.id, 'build_id': build.id}) + if not self.env['runbot.commit.export'].search([('build_id', '=', build.id), ('commit_id', '=', self.id)]): + self.env['runbot.commit.export'].create({'commit_id': self.id, 'build_id': build.id}) export_path = self._source_path() if os.path.isdir(export_path):