Skip to content
Snippets Groups Projects
Verified Commit f183c5c3 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Avoid filling up the RAM with dataset elements when cloning

parent d67c18b0
No related branches found
No related tags found
1 merge request!2256New DatasetSet model
This commit is part of merge request !2256. Comments created here will be created in the context of that merge request.
......@@ -1003,11 +1003,14 @@ class DatasetClone(CorpusACLMixin, CreateAPIView):
DatasetSet(dataset_id=clone.id, name=set.name)
for set in dataset.sets.all()
])
set_map = {set.name: set.id for set in cloned_sets}
# Associate all elements to the clone
DatasetElement.objects.bulk_create([
DatasetElement(element_id=elt_id, set=next(new_set for new_set in cloned_sets if new_set.name == set_name))
DatasetElement(element_id=elt_id, set=set_map[set_name])
for elt_id, set_name in DatasetElement.objects.filter(set__dataset_id=dataset.id)
.values_list("element_id", "set__name")
.iterator()
])
# Add the set counts to the API response
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment