Compare commits

...

2 commits

Author SHA1 Message Date
Simon Willison
7ecf5bf5ce Release 1.0a7
Refs #2189
2023-09-21 15:06:19 -07:00
Simon Willison
12395ba6ed Stop using parallel SQL queries for tables
Refs:
- #2189
2023-09-21 15:05:08 -07:00
4 changed files with 22 additions and 11 deletions

View file

@ -1,2 +1,2 @@
__version__ = "1.0a6"
__version__ = "1.0a7"
__version_info__ = tuple(__version__.split("."))

View file

@ -74,11 +74,10 @@ class Row:
return json.dumps(d, default=repr, indent=2)
async def _gather_parallel(*args):
return await asyncio.gather(*args)
async def _gather_sequential(*args):
async def run_sequential(*args):
# This used to be swappable for asyncio.gather() to run things in
# parallel, but this lead to hard-to-debug locking issues with
# in-memory databases: https://github.com/simonw/datasette/issues/2189
results = []
for fn in args:
results.append(await fn)
@ -1183,9 +1182,6 @@ async def table_view_data(
)
rows = rows[:page_size]
# For performance profiling purposes, ?_noparallel=1 turns off asyncio.gather
gather = _gather_sequential if request.args.get("_noparallel") else _gather_parallel
# Resolve extras
extras = _get_extras(request)
if any(k for k in request.args.keys() if k == "_facet" or k.startswith("_facet_")):
@ -1249,7 +1245,7 @@ async def table_view_data(
if not nofacet:
# Run them in parallel
facet_awaitables = [facet.facet_results() for facet in facet_instances]
facet_awaitable_results = await gather(*facet_awaitables)
facet_awaitable_results = await run_sequential(*facet_awaitables)
for (
instance_facet_results,
instance_facets_timed_out,
@ -1282,7 +1278,7 @@ async def table_view_data(
):
# Run them in parallel
facet_suggest_awaitables = [facet.suggest() for facet in facet_instances]
for suggest_result in await gather(*facet_suggest_awaitables):
for suggest_result in await run_sequential(*facet_suggest_awaitables):
suggested_facets.extend(suggest_result)
return suggested_facets

View file

@ -4,6 +4,20 @@
Changelog
=========
.. _v1_0_a7:
1.0a7 (2023-09-21)
------------------
- Fix for a crashing bug caused by viewing the table page for a named in-memory database. (:issue:`2189`)
.. _v0_64_4:
0.64.4 (2023-09-21)
-------------------
- Fix for a crashing bug caused by viewing the table page for a named in-memory database. (:issue:`2189`)
.. _v1_0_a6:
1.0a6 (2023-09-07)

View file

@ -1317,6 +1317,7 @@ This example uses the :ref:`register_routes() <plugin_register_routes>` plugin h
(r"/parallel-queries$", parallel_queries),
]
Note that running parallel SQL queries in this way has `been known to cause problems in the past <https://github.com/simonw/datasette/issues/2189>`__, so treat this example with caution.
Adding ``?_trace=1`` will show that the trace covers both of those child tasks.