Renamed ?_sql_time_limit_ms= to ?_timelimit, closes #242

This commit is contained in:
Simon Willison 2018-05-01 17:11:46 -07:00 committed by Simon Willison
commit 349e262bb1
4 changed files with 8 additions and 8 deletions

View file

@ -358,8 +358,8 @@ class BaseView(RenderMixin):
params[named_parameter] = '' params[named_parameter] = ''
extra_args = {} extra_args = {}
if params.get('_sql_time_limit_ms'): if params.get('_timelimit'):
extra_args['custom_time_limit'] = int(params['_sql_time_limit_ms']) extra_args['custom_time_limit'] = int(params['_timelimit'])
rows, truncated, description = await self.execute( rows, truncated, description = await self.execute(
name, sql, params, truncate=True, **extra_args name, sql, params, truncate=True, **extra_args
) )
@ -894,8 +894,8 @@ class TableView(RowTableShared):
offset=offset, offset=offset,
) )
if request.raw_args.get('_sql_time_limit_ms'): if request.raw_args.get('_timelimit'):
extra_args['custom_time_limit'] = int(request.raw_args['_sql_time_limit_ms']) extra_args['custom_time_limit'] = int(request.raw_args['_timelimit'])
rows, truncated, description = await self.execute( rows, truncated, description = await self.execute(
name, sql, params, truncate=True, **extra_args name, sql, params, truncate=True, **extra_args

View file

@ -154,7 +154,7 @@ The Datasette table view takes a number of special querystring arguments:
You can pass multiple ``_group_count`` columns to return counts against You can pass multiple ``_group_count`` columns to return counts against
unique combinations of those columns. unique combinations of those columns.
``?_sql_time_limit_ms=MS`` ``?_timelimit=MS``
Sets a custom time limit for the query in ms. You can use this for optimistic Sets a custom time limit for the query in ms. You can use this for optimistic
queries where you would like Datasette to give up if the query takes too queries where you would like Datasette to give up if the query takes too
long, for example if you want to implement autocomplete search but only if long, for example if you want to implement autocomplete search but only if

View file

@ -62,9 +62,9 @@ If this time limit is too short for you, you can customize it using the
datasette mydatabase.db --sql_time_limit_ms=3500 datasette mydatabase.db --sql_time_limit_ms=3500
You can optionally set a lower time limit for an individual query using the You can optionally set a lower time limit for an individual query using the
``_sql_time_limit_ms`` query string argument:: ``_timelimit`` query string argument::
/my-database/my-table?qSpecies=44&_sql_time_limit_ms=100 /my-database/my-table?qSpecies=44&_timelimit=100
This would set the time limit to 100ms for that specific query. This feature This would set the time limit to 100ms for that specific query. This feature
is useful if you are working with databases of unknown size and complexity - is useful if you are working with databases of unknown size and complexity -

View file

@ -269,7 +269,7 @@ def test_custom_sql_time_limit(app_client):
) )
assert 200 == response.status assert 200 == response.status
response = app_client.get( response = app_client.get(
'/test_tables.json?sql=select+sleep(0.01)&_sql_time_limit_ms=5', '/test_tables.json?sql=select+sleep(0.01)&_timelimit=5',
gather_request=False gather_request=False
) )
assert 400 == response.status assert 400 == response.status