mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Don't execute facets/counts for _shape=array or object, closes #263
This commit is contained in:
parent
a18e8641bc
commit
0539bf0816
2 changed files with 15 additions and 7 deletions
|
|
@ -379,6 +379,13 @@ class TableView(RowTableShared):
|
||||||
if is_view:
|
if is_view:
|
||||||
order_by = ""
|
order_by = ""
|
||||||
|
|
||||||
|
nocount = request.args.get("_nocount")
|
||||||
|
nofacet = request.args.get("_nofacet")
|
||||||
|
|
||||||
|
if request.args.get("_shape") in ("array", "object"):
|
||||||
|
nocount = True
|
||||||
|
nofacet = True
|
||||||
|
|
||||||
# Ensure we don't drop anything with an empty value e.g. ?name__exact=
|
# Ensure we don't drop anything with an empty value e.g. ?name__exact=
|
||||||
args = MultiParams(
|
args = MultiParams(
|
||||||
urllib.parse.parse_qs(request.query_string, keep_blank_values=True)
|
urllib.parse.parse_qs(request.query_string, keep_blank_values=True)
|
||||||
|
|
@ -697,11 +704,7 @@ class TableView(RowTableShared):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (
|
if count_sql and filtered_table_rows_count is None and not nocount:
|
||||||
count_sql
|
|
||||||
and filtered_table_rows_count is None
|
|
||||||
and not request.args.get("_nocount")
|
|
||||||
):
|
|
||||||
try:
|
try:
|
||||||
count_rows = list(await db.execute(count_sql, from_sql_params))
|
count_rows = list(await db.execute(count_sql, from_sql_params))
|
||||||
filtered_table_rows_count = count_rows[0][0]
|
filtered_table_rows_count = count_rows[0][0]
|
||||||
|
|
@ -735,7 +738,7 @@ class TableView(RowTableShared):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if not request.args.get("_nofacet"):
|
if not nofacet:
|
||||||
for facet in facet_instances:
|
for facet in facet_instances:
|
||||||
(
|
(
|
||||||
instance_facet_results,
|
instance_facet_results,
|
||||||
|
|
@ -833,7 +836,7 @@ class TableView(RowTableShared):
|
||||||
self.ds.setting("suggest_facets")
|
self.ds.setting("suggest_facets")
|
||||||
and self.ds.setting("allow_facet")
|
and self.ds.setting("allow_facet")
|
||||||
and not _next
|
and not _next
|
||||||
and not request.args.get("_nofacet")
|
and not nofacet
|
||||||
):
|
):
|
||||||
for facet in facet_instances:
|
for facet in facet_instances:
|
||||||
suggested_facets.extend(await facet.suggest())
|
suggested_facets.extend(await facet.suggest())
|
||||||
|
|
|
||||||
|
|
@ -1692,6 +1692,11 @@ def test_nocount(app_client, nocount, expected_count):
|
||||||
assert response.json["filtered_table_rows_count"] == expected_count
|
assert response.json["filtered_table_rows_count"] == expected_count
|
||||||
|
|
||||||
|
|
||||||
|
def test_nocount_nofacet_if_shape_is_object(app_client):
|
||||||
|
response = app_client.get("/fixtures/facetable.json?_trace=1&_shape=object")
|
||||||
|
assert "count(*)" not in response.text
|
||||||
|
|
||||||
|
|
||||||
def test_expand_labels(app_client):
|
def test_expand_labels(app_client):
|
||||||
response = app_client.get(
|
response = app_client.get(
|
||||||
"/fixtures/facetable.json?_shape=object&_labels=1&_size=2"
|
"/fixtures/facetable.json?_shape=object&_labels=1&_size=2"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue