summaryrefslogtreecommitdiff
path: root/django/db/models/loading.py
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2009-12-16 21:25:00 +0000
committerLuke Plant <L.Plant.98@cantab.net>2009-12-16 21:25:00 +0000
commitb38e678dae65823c58cb2be2ac6e4671af524282 (patch)
tree5b439fe040ec1a4d040023c22950b70547591cac /django/db/models/loading.py
parentc90b15e1d64d9561243f976ea42c763e0640d9fa (diff)
Fixed #12389 - performance enhancement of get_models()
Thanks to Travis Cline for the patch, which gives about 35% speed increase for the testsuite (with SQLite in-memory DB). git-svn-id: http://code.djangoproject.com/svn/django/trunk@11883 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/loading.py')
-rw-r--r--django/db/models/loading.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/django/db/models/loading.py b/django/db/models/loading.py
index 4ab1d5005a..f86b691cc9 100644
--- a/django/db/models/loading.py
+++ b/django/db/models/loading.py
@@ -35,6 +35,7 @@ class AppCache(object):
postponed = [],
nesting_level = 0,
write_lock = threading.RLock(),
+ _get_models_cache = {},
)
def __init__(self):
@@ -140,6 +141,11 @@ class AppCache(object):
explicit intermediate table) are not included. However, if you
specify include_auto_created=True, they will be.
"""
+ cache_key = (app_mod, include_auto_created)
+ try:
+ return self._get_models_cache[cache_key]
+ except KeyError:
+ pass
self._populate()
if app_mod:
model_list = self.app_models.get(app_mod.__name__.split('.')[-2], SortedDict()).values()
@@ -148,7 +154,8 @@ class AppCache(object):
for app_entry in self.app_models.itervalues():
model_list.extend(app_entry.values())
if not include_auto_created:
- return filter(lambda o: not o._meta.auto_created, model_list)
+ model_list = filter(lambda o: not o._meta.auto_created, model_list)
+ self._get_models_cache[cache_key] = model_list
return model_list
def get_model(self, app_label, model_name, seed_cache=True):
@@ -183,6 +190,7 @@ class AppCache(object):
if os.path.splitext(fname1)[0] == os.path.splitext(fname2)[0]:
continue
model_dict[model_name] = model
+ self._get_models_cache.clear()
cache = AppCache()