Fixed #3459: Django no longer runs SET TIME ZONE for every query when using Postgres. This should result in a pretty noticible speedup for Postgres users, so many thanks to Jack Moffitt for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4573 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5c17b42772
commit
dcdaa4ac3c
|
@ -60,7 +60,9 @@ class DatabaseWrapper(local):
|
|||
|
||||
def cursor(self):
|
||||
from django.conf import settings
|
||||
set_tz = False
|
||||
if self.connection is None:
|
||||
set_tz = True
|
||||
if settings.DATABASE_NAME == '':
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
raise ImproperlyConfigured, "You need to specify DATABASE_NAME in your Django settings file."
|
||||
|
@ -76,6 +78,7 @@ class DatabaseWrapper(local):
|
|||
self.connection = Database.connect(conn_string, **self.options)
|
||||
self.connection.set_isolation_level(1) # make transactions transparent to all cursors
|
||||
cursor = self.connection.cursor()
|
||||
if set_tz:
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
cursor = UnicodeCursorWrapper(cursor, settings.DEFAULT_CHARSET)
|
||||
if settings.DEBUG:
|
||||
|
|
|
@ -28,7 +28,9 @@ class DatabaseWrapper(local):
|
|||
|
||||
def cursor(self):
|
||||
from django.conf import settings
|
||||
set_tz = False
|
||||
if self.connection is None:
|
||||
set_tz = True
|
||||
if settings.DATABASE_NAME == '':
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
raise ImproperlyConfigured, "You need to specify DATABASE_NAME in your Django settings file."
|
||||
|
@ -45,6 +47,7 @@ class DatabaseWrapper(local):
|
|||
self.connection.set_isolation_level(1) # make transactions transparent to all cursors
|
||||
cursor = self.connection.cursor()
|
||||
cursor.tzinfo_factory = None
|
||||
if set_tz:
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
if settings.DEBUG:
|
||||
return util.CursorDebugWrapper(cursor, self)
|
||||
|
|
Loading…
Reference in New Issue