Created
April 10, 2009 20:54
-
-
Save tmc/93287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 03573a3876a39de5766082c3557b03e3e7134009 Mon Sep 17 00:00:00 2001 | |
From: Travis Cline <travis.cline@gmail.com> | |
Date: Fri, 10 Apr 2009 15:13:35 -0500 | |
Subject: [PATCH] added memoization of get_models for performance | |
--- | |
django/db/models/loading.py | 3 +++ | |
1 files changed, 3 insertions(+), 0 deletions(-) | |
diff --git a/django/db/models/loading.py b/django/db/models/loading.py | |
index e07aab4..2743f86 100644 | |
--- a/django/db/models/loading.py | |
+++ b/django/db/models/loading.py | |
@@ -4,6 +4,7 @@ from django.conf import settings | |
from django.core.exceptions import ImproperlyConfigured | |
from django.utils.datastructures import SortedDict | |
from django.utils.importlib import import_module | |
+from django.utils.functional import memoize | |
import sys | |
import os | |
@@ -35,6 +36,7 @@ class AppCache(object): | |
postponed = [], | |
nesting_level = 0, | |
write_lock = threading.RLock(), | |
+ _get_models_cache = {} | |
) | |
def __init__(self): | |
@@ -144,6 +146,7 @@ class AppCache(object): | |
for app_entry in self.app_models.itervalues(): | |
model_list.extend(app_entry.values()) | |
return model_list | |
+ get_models = memoize(get_models, __shared_state['_get_models_cache'], 2) | |
def get_model(self, app_label, model_name, seed_cache=True): | |
""" | |
-- | |
1.6.2.8.g9a668 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment