Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit f544d988962bb9b815d53431bfb1b8c32788a1d6 1 parent 29de7ee
@alex alex authored
Showing with 6 additions and 7 deletions.
  1. +6 −7 django/db/backends/__init__.py
View
13 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 @@ def close(self):
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 @@ def compiler(self, compiler_name):
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):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.