1

I have MEDIA files stored in S3 bucket and I noticed that REST API responses are very slow. What I also noticed is that Django tries to access the S3 when I do Model.objects.all().

Why it does that? Doesn't it store the URL in the database so it doesn't have to access S3 storage unless the URL is explicitly fetched (on the frontend side)?

DEFAULT_FILE_STORAGE = 'project.storage_backends.MediaStorage'

from storages.backends.s3boto3 import S3Boto3Storage

class MediaStorage(S3Boto3Storage):
    location = 'media'
    file_overwrite = False

The image field:

image = models.ImageField(upload_to='images', max_length=2048, null=True, blank=True, height_field='image_height',
                          width_field='image_width')
image_height = models.PositiveSmallIntegerField(null=True, blank=True)
image_width = models.PositiveSmallIntegerField(null=True, blank=True)
Milano
  • 18,048
  • 37
  • 153
  • 353
  • Are you sure the query accesses the S3 or you have some sort of a serializer that does something with the file? Can you put a break point after the query and check if it hits to the S3? – Cagatay Barin Aug 29 '21 at 19:39

0 Answers0