Stop counting at 10,000 rows when listing tables, refs #2398

main
Simon Willison 2024-08-21 14:58:29 -07:00
rodzic bc46066f9d
commit dc1d152476
3 zmienionych plików z 7 dodań i 3 usunięć

Wyświetl plik

@ -29,6 +29,9 @@ AttachedDatabase = namedtuple("AttachedDatabase", ("seq", "name", "file"))
class Database:
# For table counts stop at this many rows:
count_limit = 10000
def __init__(
self,
ds,
@ -376,7 +379,7 @@ class Database:
try:
table_count = (
await self.execute(
f"select count(*) from [{table}]",
f"select count(*) from (select * from [{table}] limit {self.count_limit + 1})",
custom_time_limit=limit,
)
).rows[0][0]

Wyświetl plik

@ -60,7 +60,7 @@
<div class="db-table">
<h3><a href="{{ urls.table(database, table.name) }}">{{ table.name }}</a>{% if table.private %} 🔒{% endif %}{% if table.hidden %}<em> (hidden)</em>{% endif %}</h3>
<p><em>{% for column in table.columns %}{{ column }}{% if not loop.last %}, {% endif %}{% endfor %}</em></p>
<p>{% if table.count is none %}Many rows{% else %}{{ "{:,}".format(table.count) }} row{% if table.count == 1 %}{% else %}s{% endif %}{% endif %}</p>
<p>{% if table.count is none %}Many rows{% elif table.count == count_limit + 1 %}&gt;{{ "{:,}".format(count_limit) }} rows{% else %}{{ "{:,}".format(table.count) }} row{% if table.count == 1 %}{% else %}s{% endif %}{% endif %}</p>
</div>
{% endif %}
{% endfor %}

Wyświetl plik

@ -159,6 +159,7 @@ class DatabaseView(View):
"show_hidden": request.args.get("_show_hidden"),
"editable": True,
"metadata": metadata,
"count_limit": db.count_limit,
"allow_download": datasette.setting("allow_download")
and not db.is_mutable
and not db.is_memory,
@ -272,7 +273,7 @@ class QueryContext:
async def get_tables(datasette, request, db):
tables = []
database = db.name
table_counts = await db.table_counts(5)
table_counts = await db.table_counts(100)
hidden_table_names = set(await db.hidden_table_names())
all_foreign_keys = await db.get_all_foreign_keys()