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
This commit is contained in:
parent
29de7ee9cb
commit
f544d98896
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue