Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the code for retrieving annotations #7748

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions cvat/apps/dataset_manager/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,7 @@ def _extend_attributes(attributeval_set, default_attribute_values):
]))

def _init_tags_from_db(self):
db_tags = self.db_job.labeledimage_set.prefetch_related(
"label",
"labeledimageattributeval_set"
).values(
db_tags = self.db_job.labeledimage_set.values(
'id',
'frame',
'label_id',
Expand All @@ -496,7 +493,7 @@ def _init_tags_from_db(self):
'labeledimageattributeval__spec_id',
'labeledimageattributeval__value',
'labeledimageattributeval__id',
).order_by('frame')
).order_by('frame').iterator(chunk_size=2000)

db_tags = _merge_table_rows(
rows=db_tags,
Expand All @@ -518,10 +515,7 @@ def _init_tags_from_db(self):
self.ir_data.tags = serializer.data

def _init_shapes_from_db(self):
db_shapes = self.db_job.labeledshape_set.prefetch_related(
"label",
"labeledshapeattributeval_set"
).values(
db_shapes = self.db_job.labeledshape_set.values(
'id',
'label_id',
'type',
Expand All @@ -537,7 +531,7 @@ def _init_shapes_from_db(self):
'labeledshapeattributeval__spec_id',
'labeledshapeattributeval__value',
'labeledshapeattributeval__id',
).order_by('frame')
).order_by('frame').iterator(chunk_size=2000)

db_shapes = _merge_table_rows(
rows=db_shapes,
Expand Down Expand Up @@ -572,11 +566,7 @@ def _init_shapes_from_db(self):
self.ir_data.shapes = serializer.data

def _init_tracks_from_db(self):
db_tracks = self.db_job.labeledtrack_set.prefetch_related(
"label",
"labeledtrackattributeval_set",
"trackedshape_set__trackedshapeattributeval_set"
).values(
db_tracks = self.db_job.labeledtrack_set.values(
"id",
"frame",
"label_id",
Expand All @@ -597,7 +587,7 @@ def _init_tracks_from_db(self):
"trackedshape__trackedshapeattributeval__spec_id",
"trackedshape__trackedshapeattributeval__value",
"trackedshape__trackedshapeattributeval__id",
).order_by('id', 'trackedshape__frame')
).order_by('id', 'trackedshape__frame').iterator(chunk_size=2000)

db_tracks = _merge_table_rows(
rows=db_tracks,
Expand Down
Loading