Implemented PostgreSQL version as a cached property.

This commit is contained in:
Aymeric Augustin 2013-02-18 22:49:59 +01:00
parent 7b8529d206
commit 21765c0a6c
1 changed files with 4 additions and 7 deletions

View File

@ -14,6 +14,7 @@ from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation
from django.db.backends.postgresql_psycopg2.version import get_version
from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
from django.utils.encoding import force_str
from django.utils.functional import cached_property
from django.utils.safestring import SafeText, SafeBytes
from django.utils import six
from django.utils.timezone import utc
@ -121,7 +122,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.creation = DatabaseCreation(self)
self.introspection = DatabaseIntrospection(self)
self.validation = BaseDatabaseValidation(self)
self._pg_version = None
def check_constraints(self, table_names=None):
"""
@ -150,11 +150,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
)
raise
def _get_pg_version(self):
if self._pg_version is None:
self._pg_version = get_version(self.connection)
return self._pg_version
pg_version = property(_get_pg_version)
@cached_property
def pg_version(self):
return get_version(self.connection)
def get_connection_params(self):
settings_dict = self.settings_dict
@ -202,7 +200,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
self.connection.cursor().execute(
self.ops.set_time_zone_sql(), [tz])
self.connection.set_isolation_level(self.isolation_level)
self._get_pg_version()
def create_cursor(self):
cursor = self.connection.cursor()