Fixed #23152 -- Added support for transactional Spatialite metadata initialization.

Thanks Doug Goldstein for the initial patch.
This commit is contained in:
Tim Graham 2014-10-30 13:52:42 -04:00
parent eb4f6de980
commit 57e40551e4
3 changed files with 13 additions and 1 deletions

View File

@ -13,6 +13,7 @@ from django.contrib.gis.db.backends.spatialite.introspection import SpatiaLiteIn
from django.contrib.gis.db.backends.spatialite.operations import SpatiaLiteOperations
from django.contrib.gis.db.backends.spatialite.schema import SpatialiteSchemaEditor
from django.utils import six
from django.utils.functional import cached_property
class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures):
@ -20,6 +21,13 @@ class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures):
# SpatiaLite can only count vertices in LineStrings
supports_num_points_poly = False
@cached_property
def supports_initspatialmetadata_with_transactions(self):
# SpatiaLite 4.1+ support initializing all metadata in one transaction
# which can result in a significant performance improvement when
# creating the database.
return self.connection.ops.spatial_version >= (4, 1, 0)
class DatabaseWrapper(SQLiteDatabaseWrapper):
SchemaEditorClass = SpatialiteSchemaEditor

View File

@ -36,4 +36,5 @@ class SpatiaLiteCreation(DatabaseCreation):
Creates the spatial metadata tables.
"""
cur = self.connection._cursor()
cur.execute("SELECT InitSpatialMetaData()")
arg = "1" if self.connection.features.supports_initspatialmetadata_with_transactions else ""
cur.execute("SELECT InitSpatialMetaData(%s)" % arg)

View File

@ -34,3 +34,6 @@ Bugfixes
``AlterIndexTogether`` or ``AlterUniqueTogether`` (:ticket:`23614`).
* Updated the first day of the week in the Ukrainian locale to Monday.
* Added support for transactional spatial metadata initialization on
SpatiaLite 4.1+ (:ticket:`23152`).