Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit dcdaa4ac3cd909570b56b1561ad3f22ff390a92f 1 parent 5c17b42
@jacobian jacobian authored
View
5 django/db/backends/postgresql/base.py
@@ -60,7 +60,9 @@ def __init__(self, **kwargs):
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 @@ def cursor(self):
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)
View
5 django/db/backends/postgresql_psycopg2/base.py
@@ -28,7 +28,9 @@ def __init__(self, **kwargs):
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 @@ def cursor(self):
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
Please sign in to comment.
Something went wrong with that request. Please try again.