From 0243c73462c6179a42074a09fedb3f56bee6291c Mon Sep 17 00:00:00 2001 From: Roland Szabo Date: Thu, 8 Jul 2021 13:05:50 +0300 Subject: [PATCH 1/2] Remove unneeded query Bulk create returns the created objects in the same order as they have been added. In Postgres, the query was wrong, because ordering was not guaranteed. --- backend/api/tasks.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/api/tasks.py b/backend/api/tasks.py index f97f9525..a23983d7 100644 --- a/backend/api/tasks.py +++ b/backend/api/tasks.py @@ -62,10 +62,8 @@ class DataFactory: self.data_class(project=project, **example.data) for example in examples ] - now = datetime.datetime.now() - self.data_class.objects.bulk_create(dataset) - ids = self.data_class.objects.filter(created_at__gte=now) - return list(ids) + results = self.data_class.objects.bulk_create(dataset) + return results def create_annotation(self, examples, ids, user, project): mapping = {label.text: label.id for label in project.labels.all()} From 62bc03f6c1c8ec81ad8fdcf17ba4411316bea035 Mon Sep 17 00:00:00 2001 From: Roland Szabo Date: Thu, 8 Jul 2021 13:25:40 +0300 Subject: [PATCH 2/2] Remove unneed import --- backend/api/tasks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/api/tasks.py b/backend/api/tasks.py index a23983d7..e05c303e 100644 --- a/backend/api/tasks.py +++ b/backend/api/tasks.py @@ -1,4 +1,3 @@ -import datetime import itertools from celery import shared_task