jsondatastore: optimize SQL queries (#68620)
- sort only when needed - filter on PG side to reduce network usage (and allow for indexing later if needed)
This commit is contained in:
parent
18dd57232a
commit
45c45fb534
|
@ -52,9 +52,6 @@ class JsonData(models.Model):
|
|||
creation_datetime = models.DateTimeField(auto_now_add=True)
|
||||
last_update_datetime = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['text']
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
text_value_template = self.datastore.text_value_template
|
||||
if text_value_template:
|
||||
|
@ -95,7 +92,7 @@ class JsonDataStore(BaseResource):
|
|||
},
|
||||
)
|
||||
def list(self, request, name_id=None, q=None, **kwargs):
|
||||
objects = JsonData.objects.filter(datastore=self)
|
||||
objects = JsonData.objects.filter(datastore=self).order_by('text')
|
||||
if name_id is not None:
|
||||
objects = objects.filter(name_id=name_id)
|
||||
if q:
|
||||
|
@ -186,7 +183,8 @@ class JsonDataStore(BaseResource):
|
|||
objects = JsonData.objects.filter(datastore=self)
|
||||
if name_id is not None:
|
||||
objects = objects.filter(name_id=name_id)
|
||||
for data in objects:
|
||||
if data.content and data.content.get(attribute) == value:
|
||||
return data.to_json()
|
||||
objects = objects.filter(content__contains={attribute: value})
|
||||
data = objects.first()
|
||||
if data is not None:
|
||||
return data.to_json()
|
||||
raise APIError('no such object')
|
||||
|
|
Loading…
Reference in New Issue