Optimize indexing request
This commit is contained in:
parent
a91ba7e6f3
commit
9dae8832cd
|
|
@ -78,6 +78,12 @@ class ProductQuerySet(models.QuerySet):
|
|||
return self.select_related('product_type', 'establishment') \
|
||||
.prefetch_related('product_type__subtypes')
|
||||
|
||||
def with_es_related(self):
|
||||
"""Returns qs with related for ES indexing."""
|
||||
return self.with_base_related().prefetch_related('tags', 'classifications', 'classifications__tags',
|
||||
'classifications__type', 'classifications_standard',
|
||||
'standards').select_related('wine_region', 'wine_sub_region')
|
||||
|
||||
def common(self):
|
||||
return self.filter(category=self.model.COMMON)
|
||||
|
||||
|
|
|
|||
|
|
@ -51,18 +51,6 @@ class ProductDocument(Document):
|
|||
properties={
|
||||
'label': fields.ObjectField(attr='label_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
'value': fields.KeywordField(),
|
||||
'category': fields.ObjectField(properties={
|
||||
'label': fields.ObjectField(attr='label_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
'public': fields.BooleanField(),
|
||||
'index_name': fields.KeywordField(),
|
||||
'value_type': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
multi=True
|
||||
),
|
||||
|
|
@ -85,18 +73,6 @@ class ProductDocument(Document):
|
|||
properties={
|
||||
'label': fields.ObjectField(attr='label_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
'value': fields.KeywordField(),
|
||||
'category': fields.ObjectField(properties={
|
||||
'label': fields.ObjectField(attr='label_indexing', properties=OBJECT_FIELD_PROPERTIES),
|
||||
'public': fields.BooleanField(),
|
||||
'index_name': fields.KeywordField(),
|
||||
'value_type': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
multi=True
|
||||
)
|
||||
|
|
@ -118,4 +94,4 @@ class ProductDocument(Document):
|
|||
related_models = [models.ProductType]
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().published().with_base_related()
|
||||
return super().get_queryset().published().with_es_related()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user