Я профилирую приложение django с панелью инструментов отладки django.
Я хочу уменьшить количество запросов к базе данных от просмотра и рендеринга.
Для каждого тега шаблона easy_thumbnail, например,
{% thumbnail coop.logo 250x250 %}
кажется, что два вызова базы данных:
SELECT ••• FROM "easy_thumbnails_source" WHERE ("easy_thumbnails_source"."name" = 'partner-logo/151119_Airlines_Logo_PNG.png' AND "easy_thumbnails_source"."storage_hash" = 'c536f7b8a65dd208e93ec823d3bce653')
Duplicated 36 times.
SELECT ••• FROM "easy_thumbnails_thumbnail" WHERE ("easy_thumbnails_thumbnail"."name" = 'partner-logo/151119_Airlines_Logo_PNG.png.250x250_q85.jpg' AND "easy_thumbnails_thumbnail"."source_id" = 1525 AND "easy_thumbnails_thumbnail"."storage_hash" = '5e4fc44a8986f46175c0675df42cf544')
Duplicated 38 times.
а) Почему два звонка? Можно ли это уменьшить?
б) Почему они дублируются так много раз? Это стоит мне производительности?
Edit:
model.py
class Cooperation(models.Model):
...
logo = models.ImageField(upload_to='partner-logo/', null=True, blank=True)
...
Traces:
table source:
/projects/primomedico.new/frontend/views.py in home(646)
return render(request, 'home.html', context)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/templatetags/thumbnail.py in render(116)
thumbnail = get_thumbnailer(source).get_thumbnail(opts)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/files.py in get_thumbnail(512)
thumbnail = self.get_existing_thumbnail(thumbnail_options)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/files.py in get_existing_thumbnail(478)
exists = self.thumbnail_exists(filename)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/files.py in thumbnail_exists(593)
source = self.get_source_cache()
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/files.py in get_source_cache(628)
check_cache_miss=self.thumbnail_check_cache_miss)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/models.py in get_file(26)
obj = manager.get(**kwargs)
table thumbnail:
/projects/primomedico.new/frontend/views.py in home(646)
return render(request, 'home.html', context)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/templatetags/thumbnail.py in render(116)
thumbnail = get_thumbnailer(source).get_thumbnail(opts)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/files.py in get_thumbnail(512)
thumbnail = self.get_existing_thumbnail(thumbnail_options)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/files.py in get_existing_thumbnail(478)
exists = self.thumbnail_exists(filename)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/files.py in thumbnail_exists(609)
thumbnail = self.get_thumbnail_cache(thumbnail_name)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/files.py in get_thumbnail_cache(639)
check_cache_miss=self.thumbnail_check_cache_miss)
/projects/primomedico.new/.venv/lib/python3.5/site-packages/easy_thumbnails/models.py in get_file(26)
obj = manager.get(**kwargs)