From f544d988962bb9b815d53431bfb1b8c32788a1d6 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 12 Jan 2011 13:39:31 +0000 Subject: [PATCH] 2 small optimizations: a) move an import out of a function, b) remove a cache that did nothing, tiny tiny speed up on CPython, but a big one on PyPy git-svn-id: http://code.djangoproject.com/svn/django/trunk@15175 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/__init__.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 971e3622ed..d2d5c7d056 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -1,11 +1,13 @@ import decimal from threading import local +from django.conf import settings from django.db import DEFAULT_DB_ALIAS from django.db.backends import util from django.utils import datetime_safe from django.utils.importlib import import_module + class BaseDatabaseWrapper(local): """ Represents a database connection. @@ -73,7 +75,6 @@ class BaseDatabaseWrapper(local): self.connection = None def cursor(self): - from django.conf import settings cursor = self._cursor() if (self.use_debug_cursor or (self.use_debug_cursor is None and settings.DEBUG)): @@ -205,7 +206,7 @@ class BaseDatabaseOperations(object): compiler_module = "django.db.models.sql.compiler" def __init__(self): - self._cache = {} + self._cache = None def autoinc_sql(self, table, column): """ @@ -388,11 +389,9 @@ class BaseDatabaseOperations(object): in the namespace corresponding to the `compiler_module` attribute on this backend. """ - if compiler_name not in self._cache: - self._cache[compiler_name] = getattr( - import_module(self.compiler_module), compiler_name - ) - return self._cache[compiler_name] + if self._cache is None: + self._cache = import_module(self.compiler_module) + return getattr(self._cache, compiler_name) def quote_name(self, name): """