[Django]-Large json data in django model slows down any query

2👍

Fetching the object likely takes too much time. You can work with .only(…) [Django-doc] to only retrieve the primary key and some_field:

obj = SomeModel.objects.only('pk', 'some_field').get(pk=some_pk)
obj.some_field = "ice cream"
obj.save()

You can also .update(…) [Django-doc] in a queryset, in that case the object is never loaded in memory, so:

SomeModel.objects.filter(pk=some_pk).update(some_field='ice cream')

1👍

Find the JSON fields that are most commonly searched on. Copy them into separate, MySQL, columns. Then change the code to fetch on them. This should speed up locating the desired rows, and only then does it get a steam shovel to copy the JSON to the app.

If many Selects only fetch a small collection of fields, also copy those out of JSON into MySQL columns. Then, if you can avoid fetching the JSON whale, such Selects will be faster.

I hope you are not actually Updating columns in the JSON; that would be miserably slow.

Leave a comment