This document summarizes Andy McKay's presentation on the anatomy of Mozilla's large Django site. It discusses performance optimizations including caching, reducing SQL queries, async tasks with Celery, and localization. It also covers code reuse through libraries like Bleach and JavaScript testing. Testing, linting, and continuous integration with Hudson were also mentioned.
1 of 80
Downloaded 37 times
More Related Content
Anatomy of a Large Django site
1. Anatomy of a large
Django site
Andy McKay Mozilla
mozilla
20. Cache machine
http://bit.ly/cache-machine
Credit: http://www.?ickr.com/photos/mwichary/4063534688/
mozilla
21. from django.db import models
import caching.base
class Addon(caching.base.CachingMixin,
models.Model):
...
status = models.IntegerField()
objects = caching.base.CachingManager()
available as a mixin
need to addin the custom
manager
mozilla
34. @staticmethod
def transformer(addons):
addon_dict = dict((a.id, a) for a in addons)
vs = filter(None, (a.current_version_id for a in addons)
versions = list(Version.objects.filter(id__in=vs))
for version in versions:
addon_dict[version.addon_id].current_version = version
slightly outdated
example
mozilla
35. big SQL statements... :(
14313 character
Home page
20+ addons
~14 sql queries
mozilla
36. Update
Called on startup
about:con?g extensions.update.url
mozilla
71. test('English', function() {
??? z.refreshL10n('en-us');
??? equals($('textarea:visible', this.sandbox).text().trim(),
?????????? 'Firebug integrates with Firefox to put ' +
'a wealth of development tools...');
});
mozilla
73. So we use hudson for CI,
but haven¡¯t got the
automated tests in yet
Hoping to do this via
jstestnet
Use HudsonJenkins
http://bit.ly/jstestnet
mozilla
74. pep 8
py flakes
MacCabe
Flake8
http://bit.ly/?ake8
Credit: http://www.?ickr.com/photos/nebarnix/357779131/
mozilla
75. ~/sandboxes/zamboni(632719) $ flake8 apps/editors/tasks.py
apps/editors/tasks.py:1: 'datetime' imported but unused
apps/editors/tasks.py:3: 'stat' imported but unused
mozilla
76. Playdoh
http://bit.ly/mozilla-playdoh
fred wenzel
Credit: http://www.?ickr.com/photos/ahmee/97960570/
mozilla
78. Celery support
Jinja2 support
Simple migrations
By default:
SHA-512 password hashing
X-Frame-Options: DENY
secure and httponly ?ags on cookies
fred wenzel
mozilla
79. Take inspiration from...
but not the best for you
for example jinja2 which
makes integration with
lots of django addons
possible, but a bit harder
mozilla
80. Questions?
@andymckay
andym@mozilla.com
andym on irc.freenode.net, irc.mozilla.org
mozilla