Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jacob Kaplan-Moss authored February 25, 2007
5  django/db/backends/postgresql/base.py
@@ -60,7 +60,9 @@ def __init__(self, **kwargs):
60 60
 
61 61
     def cursor(self):
62 62
         from django.conf import settings
  63
+        set_tz = False
63 64
         if self.connection is None:
  65
+            set_tz = True
64 66
             if settings.DATABASE_NAME == '':
65 67
                 from django.core.exceptions import ImproperlyConfigured
66 68
                 raise ImproperlyConfigured, "You need to specify DATABASE_NAME in your Django settings file."
@@ -76,7 +78,8 @@ def cursor(self):
76 78
             self.connection = Database.connect(conn_string, **self.options)
77 79
             self.connection.set_isolation_level(1) # make transactions transparent to all cursors
78 80
         cursor = self.connection.cursor()
79  
-        cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
  81
+        if set_tz:
  82
+            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
80 83
         cursor = UnicodeCursorWrapper(cursor, settings.DEFAULT_CHARSET)
81 84
         if settings.DEBUG:
82 85
             return util.CursorDebugWrapper(cursor, self)
5  django/db/backends/postgresql_psycopg2/base.py
@@ -28,7 +28,9 @@ def __init__(self, **kwargs):
28 28
 
29 29
     def cursor(self):
30 30
         from django.conf import settings
  31
+        set_tz = False
31 32
         if self.connection is None:
  33
+            set_tz = True
32 34
             if settings.DATABASE_NAME == '':
33 35
                 from django.core.exceptions import ImproperlyConfigured
34 36
                 raise ImproperlyConfigured, "You need to specify DATABASE_NAME in your Django settings file."
@@ -45,7 +47,8 @@ def cursor(self):
45 47
             self.connection.set_isolation_level(1) # make transactions transparent to all cursors
46 48
         cursor = self.connection.cursor()
47 49
         cursor.tzinfo_factory = None
48  
-        cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
  50
+        if set_tz:
  51
+            cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE])
49 52
         if settings.DEBUG:
50 53
             return util.CursorDebugWrapper(cursor, self)
51 54
         return cursor

0 notes on commit dcdaa4a

Please sign in to comment.
Something went wrong with that request. Please try again.