mirror of https://github.com/django/django.git
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,7 +78,8 @@ 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()
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
if set_tz:
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
cursor = UnicodeCursorWrapper(cursor, settings.DEFAULT_CHARSET)
|
||||
if settings.DEBUG:
|
||||
return util.CursorDebugWrapper(cursor, self)
|
||||
|
|
|
@ -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,7 +47,8 @@ class DatabaseWrapper(local):
|
|||
self.connection.set_isolation_level(1) # make transactions transparent to all cursors
|
||||
cursor = self.connection.cursor()
|
||||
cursor.tzinfo_factory = None
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
if set_tz:
|
||||
cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
|
||||
if settings.DEBUG:
|
||||
return util.CursorDebugWrapper(cursor, self)
|
||||
return cursor
|
||||
|
|
Loading…
Reference in New Issue