From 8081ec7bb48f71c396a5d6bae6bb2cd397c4dc00 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 1 May 2018 17:11:46 -0700 Subject: [PATCH] Renamed ?_sql_time_limit_ms= to ?_timelimit, closes #242 --- datasette/app.py | 8 ++++---- docs/json_api.rst | 2 +- docs/sql_queries.rst | 4 ++-- tests/test_api.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index ec1c8cbd..75be58bc 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -358,8 +358,8 @@ class BaseView(RenderMixin): params[named_parameter] = '' extra_args = {} - if params.get('_sql_time_limit_ms'): - extra_args['custom_time_limit'] = int(params['_sql_time_limit_ms']) + if params.get('_timelimit'): + extra_args['custom_time_limit'] = int(params['_timelimit']) rows, truncated, description = await self.execute( name, sql, params, truncate=True, **extra_args ) @@ -894,8 +894,8 @@ class TableView(RowTableShared): offset=offset, ) - if request.raw_args.get('_sql_time_limit_ms'): - extra_args['custom_time_limit'] = int(request.raw_args['_sql_time_limit_ms']) + if request.raw_args.get('_timelimit'): + extra_args['custom_time_limit'] = int(request.raw_args['_timelimit']) rows, truncated, description = await self.execute( name, sql, params, truncate=True, **extra_args diff --git a/docs/json_api.rst b/docs/json_api.rst index af212ea5..aa9a914f 100644 --- a/docs/json_api.rst +++ b/docs/json_api.rst @@ -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 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 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 diff --git a/docs/sql_queries.rst b/docs/sql_queries.rst index 07276d94..e02fad3d 100644 --- a/docs/sql_queries.rst +++ b/docs/sql_queries.rst @@ -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 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 is useful if you are working with databases of unknown size and complexity - diff --git a/tests/test_api.py b/tests/test_api.py index 6d5fa40a..08763b0f 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -269,7 +269,7 @@ def test_custom_sql_time_limit(app_client): ) assert 200 == response.status 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 ) assert 400 == response.status