summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2009-04-10 17:04:35 +0000
committerAdrian Holovaty <adrian@holovaty.com>2009-04-10 17:04:35 +0000
commitfd443959df59be304a02a4de9ad93f89fab2cc4b (patch)
treee94799173a0f97fda090f6c5972ed03e45567736
parentbb75efc050a985ee1f389e85a2abd504c27c8035 (diff)
Added an SRID_CACHE to GeoDjango db/models/fields/__init__.py so that we only hit the spatial_ref_sys table once per SRID per process
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10488 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/db/models/fields/__init__.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/contrib/gis/db/models/fields/__init__.py b/django/contrib/gis/db/models/fields/__init__.py
index d4ec8a2fc9..b108c16b00 100644
--- a/django/contrib/gis/db/models/fields/__init__.py
+++ b/django/contrib/gis/db/models/fields/__init__.py
@@ -13,6 +13,10 @@ def deprecated_property(func):
warn('This attribute has been deprecated, please use "%s" instead.' % func.__name__[1:])
return property(func)
+# Local cache of the spatial_ref_sys table, which holds static data.
+# This exists so that we don't have to hit the database each time.
+SRID_CACHE = {}
+
class GeometryField(SpatialBackend.Field):
"The base GIS field -- maps to the OpenGIS Specification Geometry type."
@@ -60,7 +64,9 @@ class GeometryField(SpatialBackend.Field):
super(GeometryField, self).__init__(**kwargs) # Calling the parent initializtion function
def _populate_srid_info(self):
- self._units_cache, self._units_name_cache, self._spheroid_cache = get_srid_info(self.srid)
+ if self.srid not in SRID_CACHE:
+ SRID_CACHE[self.srid] = get_srid_info(self.srid)
+ self._units_cache, self._units_name_cache, self._spheroid_cache = SRID_CACHE[self.srid]
def _get_units(self):
if self._units_cache is None: