kopia lustrzana https://github.com/simonw/datasette
table facet_size in metadata, refs #1804
rodzic
d80775a48d
commit
8430c3bc7d
|
|
@ -102,11 +102,19 @@ class Facet:
|
|||
def get_facet_size(self):
|
||||
facet_size = self.ds.setting("default_facet_size")
|
||||
max_returned_rows = self.ds.setting("max_returned_rows")
|
||||
table_facet_size = None
|
||||
if self.table:
|
||||
tables_metadata = self.ds.metadata("tables", database=self.database) or {}
|
||||
table_metadata = tables_metadata.get(self.table) or {}
|
||||
if table_metadata:
|
||||
table_facet_size = table_metadata.get("facet_size")
|
||||
custom_facet_size = self.request.args.get("_facet_size")
|
||||
if custom_facet_size == "max":
|
||||
facet_size = max_returned_rows
|
||||
elif custom_facet_size and custom_facet_size.isdigit():
|
||||
if custom_facet_size and custom_facet_size.isdigit():
|
||||
facet_size = int(custom_facet_size)
|
||||
elif table_facet_size:
|
||||
facet_size = table_facet_size
|
||||
if facet_size == "max":
|
||||
facet_size = max_returned_rows
|
||||
return min(facet_size, max_returned_rows)
|
||||
|
||||
async def suggest(self):
|
||||
|
|
|
|||
|
|
@ -581,6 +581,23 @@ async def test_facet_size():
|
|||
)
|
||||
data5 = response5.json()
|
||||
assert len(data5["facet_results"]["city"]["results"]) == 20
|
||||
# Now try messing with facet_size in the table metadata
|
||||
ds._metadata_local = {
|
||||
"databases": {
|
||||
"test_facet_size": {"tables": {"neighbourhoods": {"facet_size": 6}}}
|
||||
}
|
||||
}
|
||||
response6 = await ds.client.get("/test_facet_size/neighbourhoods.json?_facet=city")
|
||||
data6 = response6.json()
|
||||
assert len(data6["facet_results"]["city"]["results"]) == 6
|
||||
# Setting it to max bumps it up to 50 again
|
||||
ds._metadata_local["databases"]["test_facet_size"]["tables"]["neighbourhoods"][
|
||||
"facet_size"
|
||||
] = "max"
|
||||
data7 = (
|
||||
await ds.client.get("/test_facet_size/neighbourhoods.json?_facet=city")
|
||||
).json()
|
||||
assert len(data7["facet_results"]["city"]["results"]) == 20
|
||||
|
||||
|
||||
def test_other_types_of_facet_in_metadata():
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue