Browse Source

Update repositories to speed up query

pull/1310/head
Hironsan 3 years ago
parent
commit
1e4d18a3c3
1 changed files with 23 additions and 1 deletions
  1. 24
      app/api/views/download/repositories.py

24
app/api/views/download/repositories.py

@ -18,8 +18,12 @@ class BaseRepository(abc.ABC):
class TextRepository(BaseRepository):
@property
def docs(self):
return self.project.documents.all()
def list(self, export_approved=False):
docs = self.project.documents.all()
docs = self.docs
if export_approved:
docs = docs.exclude(annotations_approved_by=None)
@ -41,6 +45,12 @@ class TextRepository(BaseRepository):
class TextClassificationRepository(TextRepository):
@property
def docs(self):
return self.project.documents.prefetch_related(
'doc_annotations__user', 'doc_annotations__label'
)
def label_per_user(self, doc) -> Dict:
label_per_user = defaultdict(list)
for a in doc.doc_annotations.all():
@ -50,6 +60,12 @@ class TextClassificationRepository(TextRepository):
class SequenceLabelingRepository(TextRepository):
@property
def docs(self):
return self.project.documents.prefetch_related(
'seq_annotations__user', 'seq_annotations__label'
)
def label_per_user(self, doc) -> Dict:
label_per_user = defaultdict(list)
for a in doc.seq_annotations.all():
@ -60,6 +76,12 @@ class SequenceLabelingRepository(TextRepository):
class Seq2seqRepository(TextRepository):
@property
def docs(self):
return self.project.documents.prefetch_related(
'seq2seq_annotations__user', 'seq2seq_annotations__text'
)
def label_per_user(self, doc) -> Dict:
label_per_user = defaultdict(list)
for a in doc.seq2seq_annotations.all():

Loading…
Cancel
Save