Back to blog index

Faster model gallery pages

The last few weeks I've been working on improving the site's performance since beginning November last year it went to the floor.

There are still some pieces that I have not found completely but I spotted one of the biggest problems. It was template rendering. The Django views were returning too basic objects on the template's rendering context and too much logic was put on the templates, so they ended up doing many related queries (hidden in methods) or template tags.

What I've been doing is pre calculate most of these variables on the view so I have better control of them and can time them, also denormalizing fields when possible.

A big offender was the model gallery page, this page shows all the pictures that have been uploaded for a bra model and shows them grouped by size.

This page was making use of Django's {% regroup %} tag, and then within the inner forloops it was accessing related models, which in many cases were the same and causing to make independent database queries to render just a simple size string.

The change was obvious, move that regroup's logic to the view, where I can make smarter use of database queries, and decreased from NxM to 3!

The next problem is pregenerated thumbnails but that's been addressed in the past.

January 15, 2014
comments powered by Disqus