Merge pull request #132 from ckan/paster-speedup

Speed up non-spatial paster commands.
This commit is contained in:
Adrià Mercader 2016-01-13 18:36:32 +01:00
commit 29abbeb1bb
1 changed files with 14 additions and 6 deletions

View File

@ -5,11 +5,10 @@ from logging import getLogger
from pylons import config from pylons import config
import shapely
from ckan import plugins as p from ckan import plugins as p
from ckan.lib.search import SearchError, PackageSearchQuery
from ckan.lib.helpers import json from ckan.lib.helpers import json
@ -38,10 +37,6 @@ def check_geoalchemy_requirement():
check_geoalchemy_requirement() check_geoalchemy_requirement()
from ckanext.spatial.lib import save_package_extent, validate_bbox, bbox_query, bbox_query_ordered
from ckanext.spatial.model.package_extent import setup as setup_model
log = getLogger(__name__) log = getLogger(__name__)
@ -73,8 +68,11 @@ class SpatialMetadata(p.SingletonPlugin):
p.implements(p.ITemplateHelpers, inherit=True) p.implements(p.ITemplateHelpers, inherit=True)
def configure(self, config): def configure(self, config):
from ckanext.spatial.model.package_extent import setup as setup_model
if not p.toolkit.asbool(config.get('ckan.spatial.testing', 'False')): if not p.toolkit.asbool(config.get('ckan.spatial.testing', 'False')):
print "*" * 100
print "Setting up the models"
setup_model() setup_model()
def update_config(self, config): def update_config(self, config):
@ -101,6 +99,8 @@ class SpatialMetadata(p.SingletonPlugin):
For a given package, looks at the spatial extent (as given in the For a given package, looks at the spatial extent (as given in the
extra "spatial" in GeoJSON format) and records it in PostGIS. extra "spatial" in GeoJSON format) and records it in PostGIS.
''' '''
from ckanext.spatial.lib import save_package_extent
if not package.id: if not package.id:
log.warning('Couldn\'t store spatial extent because no id was provided for the package') log.warning('Couldn\'t store spatial extent because no id was provided for the package')
return return
@ -139,6 +139,7 @@ class SpatialMetadata(p.SingletonPlugin):
def delete(self, package): def delete(self, package):
from ckanext.spatial.lib import save_package_extent
save_package_extent(package.id,None) save_package_extent(package.id,None)
## ITemplateHelpers ## ITemplateHelpers
@ -175,6 +176,7 @@ class SpatialQuery(p.SingletonPlugin):
return map return map
def before_index(self, pkg_dict): def before_index(self, pkg_dict):
import shapely
if pkg_dict.get('extras_spatial', None) and self.search_backend in ('solr', 'solr-spatial-field'): if pkg_dict.get('extras_spatial', None) and self.search_backend in ('solr', 'solr-spatial-field'):
try: try:
@ -235,6 +237,9 @@ class SpatialQuery(p.SingletonPlugin):
return pkg_dict return pkg_dict
def before_search(self, search_params): def before_search(self, search_params):
from ckanext.spatial.lib import validate_bbox
from ckan.lib.search import SearchError
if search_params.get('extras', None) and search_params['extras'].get('ext_bbox', None): if search_params.get('extras', None) and search_params['extras'].get('ext_bbox', None):
bbox = validate_bbox(search_params['extras']['ext_bbox']) bbox = validate_bbox(search_params['extras']['ext_bbox'])
@ -320,6 +325,8 @@ class SpatialQuery(p.SingletonPlugin):
return search_params return search_params
def _params_for_postgis_search(self, bbox, search_params): def _params_for_postgis_search(self, bbox, search_params):
from ckanext.spatial.lib import bbox_query, bbox_query_ordered
from ckan.lib.search import SearchError
# Note: This will be deprecated at some point in favour of the # Note: This will be deprecated at some point in favour of the
# Solr 4 spatial sorting capabilities # Solr 4 spatial sorting capabilities
@ -367,6 +374,7 @@ class SpatialQuery(p.SingletonPlugin):
return search_params return search_params
def after_search(self, search_results, search_params): def after_search(self, search_results, search_params):
from ckan.lib.search import PackageSearchQuery
# Note: This will be deprecated at some point in favour of the # Note: This will be deprecated at some point in favour of the
# Solr 4 spatial sorting capabilities # Solr 4 spatial sorting capabilities