I have a displays table with 147 rows. I am not doing any heavy computation on this data set I just need to get it fast from the database. For now, the load time is 3-4 seconds. Other data comes really fast, why? Does the ListApiView work slow?
@permission_classes([AllowAny])
class DisplaysList(generics.ListAPIView):
queryset = Displays.objects.all()
serializer_class = serializers.DisplaySerializer
class Displays(models.Model):
name = models.CharField(max_length=45, blank=True, null=True)
owner = models.CharField(max_length=45, blank=True, null=True)
class GeoLocation(models.Model):
id = models.CharField(primary_key=True, max_length=32,
default=generate_uuid)
display = models.ForeignKey(
Displays, on_delete=models.CASCADE, blank=True, null=True)
lat = models.DecimalField(max_digits = 30, decimal_places=20, blank=True, null=True)
lon = models.DecimalField(max_digits = 30, decimal_places=20, blank=True, null=True)
I think the issue is here, how to get efficiently geolocation?
class DisplaySerializer(serializers.ModelSerializer):
geolocation = serializers.SerializerMethodField()
def get_geolocation(self, obj):
gl = GeoLocation.objects.filter(display = obj)
gll = list(gl.values)
return gll
class Meta:
model = Displays
fields = "__all__"
list(GeoLocation.objects.select_related().filter(display=obj).values())