mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Stop counting at 10,000 rows when listing tables, refs #2398
This commit is contained in:
parent
bc46066f9d
commit
dc1d152476
3 changed files with 7 additions and 3 deletions
|
|
@ -29,6 +29,9 @@ AttachedDatabase = namedtuple("AttachedDatabase", ("seq", "name", "file"))
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
|
# For table counts stop at this many rows:
|
||||||
|
count_limit = 10000
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
ds,
|
ds,
|
||||||
|
|
@ -376,7 +379,7 @@ class Database:
|
||||||
try:
|
try:
|
||||||
table_count = (
|
table_count = (
|
||||||
await self.execute(
|
await self.execute(
|
||||||
f"select count(*) from [{table}]",
|
f"select count(*) from (select * from [{table}] limit {self.count_limit + 1})",
|
||||||
custom_time_limit=limit,
|
custom_time_limit=limit,
|
||||||
)
|
)
|
||||||
).rows[0][0]
|
).rows[0][0]
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@
|
||||||
<div class="db-table">
|
<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>
|
<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><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 %}>{{ "{:,}".format(count_limit) }} rows{% else %}{{ "{:,}".format(table.count) }} row{% if table.count == 1 %}{% else %}s{% endif %}{% endif %}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,7 @@ class DatabaseView(View):
|
||||||
"show_hidden": request.args.get("_show_hidden"),
|
"show_hidden": request.args.get("_show_hidden"),
|
||||||
"editable": True,
|
"editable": True,
|
||||||
"metadata": metadata,
|
"metadata": metadata,
|
||||||
|
"count_limit": db.count_limit,
|
||||||
"allow_download": datasette.setting("allow_download")
|
"allow_download": datasette.setting("allow_download")
|
||||||
and not db.is_mutable
|
and not db.is_mutable
|
||||||
and not db.is_memory,
|
and not db.is_memory,
|
||||||
|
|
@ -272,7 +273,7 @@ class QueryContext:
|
||||||
async def get_tables(datasette, request, db):
|
async def get_tables(datasette, request, db):
|
||||||
tables = []
|
tables = []
|
||||||
database = db.name
|
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())
|
hidden_table_names = set(await db.hidden_table_names())
|
||||||
all_foreign_keys = await db.get_all_foreign_keys()
|
all_foreign_keys = await db.get_all_foreign_keys()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue