djangosnippets.org: Latest snippets tagged with 'optimization'http://djangosnippets.org/tags/optimization/2012-12-20T14:42:52.423654-06:00Spaceless all HTML pages
2012-12-20T14:42:52.423654-06:00matrixhttp://djangosnippets.org/snippets/2867/<p>This middleware remove all space between tags and line break of all HTML pages.
Use a standard Django method. Set <em>force_spaceless</em> for dev. purpose. </p>
Freely redistributableDjango Admin Speedup for big tables on postgres
2012-12-02T08:27:17.774113-06:00potiukhttp://djangosnippets.org/snippets/2855/<p>The code is Django 1.4 version of code based on the <a href="http://djangosnippets.org/snippets/2593/">Django 1.3 snippet</a> that speeds up Django's admin pages with postgres back-end for big tables (> few hundred thousands of records).</p>
Freely redistributableFuzzy testing with assertNumQueries
2011-01-12T10:41:59.698608-06:00spookylukeyhttp://djangosnippets.org/snippets/2320/<p>Django 1.3 has an assertNumQueries method which will allows you to simply specify the number of queries you expect. Sometimes, however, specifying the exact number of queries is overkill, and makes the test too brittle. This code provides a way to make more forgiving tests.
</p>
<p>See http://lukeplant.me.uk/blog/posts/fuzzy-testing-with-assertnumqueries/
</p>
Freely redistributableget_cache_or_query - Shortcut to common cache signature
2008-05-05T15:06:04.442295-05:00menendezhttp://djangosnippets.org/snippets/738/<p>Replaces something like this:
cache_key = 'game1'
the_game = cache.get(cache_key)
if not the_game:
the_game = Game.objects.get(id=1)
cache.set(cache_key, the_game, 60<em>24</em>5)
</p>
<p>With this:
the_game = get_cache_or_query('game1', Game, seconds_to_cache=60<em>24</em>5, id=1)
</p>
Freely redistributablecaching parsed templates
2007-12-12T14:18:48.635038-06:00forgemshttp://djangosnippets.org/snippets/507/<p>Put this code somewhere in one of your INSTALLED_APPS <code>__init__.py</code> file. This code will replace the django.template.loader.get_template with cached version. Standard get_template function from django reads and parses the template code every time it's called. This version calls (if DEBUG set to False) it only once per template. After that …</p>
Freely redistributable