我正在使用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.
a)为什么两个电话?这可以减少吗? b)为什么它们重复这么多次?这会让我失去成绩吗?
编辑:
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)