Skip to content
Snippets Groups Projects
Verified Commit d98c33e5 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

More efficient SQL query to compute import batch status

parent e29cfb73
Branches
Tags
No related merge requests found
...@@ -507,6 +507,8 @@ class ImportBatch(models.Model): ...@@ -507,6 +507,8 @@ class ImportBatch(models.Model):
def update_status(self): def update_status(self):
old_status = self.status old_status = self.status
self.status = utils.compute_status(self.jobs.all()) self.status = utils.compute_status(self.jobs.all())
if self.status == old_status:
return
self.save(update_fields=['status']) self.save(update_fields=['status'])
if self.status != old_status and self.status == 'finished': if self.status != old_status and self.status == 'finished':
from . import tasks from . import tasks
......
...@@ -53,10 +53,11 @@ def guess_mimetype(f): ...@@ -53,10 +53,11 @@ def guess_mimetype(f):
def compute_status(jobs): def compute_status(jobs):
errored = any([job.status == 'errored' for job in jobs]) statuses = jobs.values_list('status', flat=True).distinct()
errored = any([status == 'errored' for status in statuses])
if errored: if errored:
return 'errored' return 'errored'
pending = any([job.status == 'pending' for job in jobs]) pending = any([status == 'pending' for status in statuses])
if pending: if pending:
return 'pending' return 'pending'
return 'finished' return 'finished'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment