Reducing sorl thumbnail sql queries?
Asked Answered
B

0

6

I'm using sorl-thumbnail to generate thumbnails for a list of images. Essentially my code looks like

{% for image in image_list %}

    {% thumbnail image.image "158x158" crop="center" as im %}

    {% endthumbnail %}

{% endfor %}

The problem is because I'm doing the thumbnail inside the for loop, every once in a while, sorl-thumbnail needs to run sql queries, which in my case, at one query per image, results in a huge db bottleneck. I need this process to be more efficient, say do all the thumbnail queries in the list at once?

So how can I make this thumbnail creation/retrieval process more efficient?

Botzow answered 2/5, 2013 at 11:57 Comment(3)
I wouldn't have thought the DB would be the bottleneck here. What makes you think it is?Cesspool
normally when I load 10+ thumbnails, the number of queries is about 6 (due to caching), when sorl thumbnails does its stuff, it goes to about 38 queries. I am not sure that the db is the bottleneck, but based on the query numbers above, I can't imagine it scaling well.Botzow
Perhaps, but they should be fast queries (i.e. < 1ms), whereas scaling an image usually takes longer than that. It's probably worth profiling some test cases with hundreds of images to see where it's actually spending most of its time.Cesspool

© 2022 - 2024 — McMap. All rights reserved.