Skip to content

Commit

Permalink
Add ANALYZE api for datapusher to use
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Oct 12, 2018
1 parent 7760a56 commit af1f95c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ckanext/datastore/logic/action.py
Expand Up @@ -651,3 +651,24 @@ def datastore_function_delete(context, data_dict):
p.toolkit.check_access('datastore_function_delete', context, data_dict)
backend = DatastoreBackend.get_active_backend()
backend.drop_function(data_dict['name'], data_dict['if_exists'])


@logic.validate(dsschema.datastore_analyze_schema)
def datastore_analyze(context, data_dict):
'''Runs postgres's ANALYZE
:param resource_id: resource id for the table that will be analyzed
:type resource_id: string
'''
p.toolkit.check_access('datastore_analyze', context, data_dict)
backend = DatastoreBackend.get_active_backend()
connection = backend._get_write_engine().connect()

result = backend.analyze(context, data_dict)
#move to backend/postgres.py
sql = 'ANALYZE "{}"'.format(data_dict['resource_id'])
try:
results = connection.execute(sql)
except sqlalchemy.exc.DatabaseError as err:
raise p.toolkit.ValidationError({
u'records': [message.split(u') ', 1)[-1]]})
4 changes: 4 additions & 0 deletions ckanext/datastore/logic/auth.py
Expand Up @@ -83,3 +83,7 @@ def datastore_function_delete(context, data_dict):
def datastore_run_triggers(context, data_dict):
'''sysadmin-only: functions can be used to skip access checks'''
return {'success': False}


def datastore_analyze(context, data_dict):
return {'success': False}
6 changes: 6 additions & 0 deletions ckanext/datastore/logic/schema.py
Expand Up @@ -196,3 +196,9 @@ def datastore_function_delete_schema():
'name': [unicode_only, not_empty],
'if_exists': [default(False), boolean_validator],
}


def datastore_analyze_schema():
return {
'resource_id': [text_type, resource_id_exists],
}

0 comments on commit af1f95c

Please sign in to comment.