- I have a Django model with 16 DecimalFields.
- I have created a ListAPIView to fetch this data.
- With ~5000 instances of this model in my db, the GET request to this api view is taking more than 15 seconds.
Model:
class MyModel(models.Model):
f1 = models.DecimalField (max_digits=8, decimal_places=3)
f2 = models.DecimalField (max_digits=8, decimal_places=3)
f3 = models.DecimalField (max_digits=8, decimal_places=3)
f4 = models.DecimalField (max_digits=8, decimal_places=3)
f5 = models.DecimalField (max_digits=8, decimal_places=3)
f6 = models.DecimalField (max_digits=8, decimal_places=3)
f7 = models.DecimalField (max_digits=8, decimal_places=3)
f8 = models.DecimalField (max_digits=8, decimal_places=3)
f9 = models.DecimalField (max_digits=8, decimal_places=3)
f10 = models.DecimalField (max_digits=8, decimal_places=3)
f11 = models.DecimalField (max_digits=8, decimal_places=3)
f12 = models.DecimalField (max_digits=8, decimal_places=3)
f13 = models.DecimalField (max_digits=8, decimal_places=3)
f14 = models.DecimalField (max_digits=8, decimal_places=3)
f15 = models.DecimalField (max_digits=8, decimal_places=3)
f16 = models.DecimalField (max_digits=8, decimal_places=3)
Serializer:
class MyModelSerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
I am not doing any filtering of the data. When I run the query in the django shell, it runs in a few ms. I assume serialization is the problem here. However, I am using the default ModelSerializer.
All of these fields are in the same table, so I don't see how there could be an N+1 issue here.
What can I do to further profile this issue? Should I expect my queries to be this slow with this many model instances?