diff --git a/datasette/database.py b/datasette/database.py index c761dad76b..da0ab1de86 100644 --- a/datasette/database.py +++ b/datasette/database.py @@ -29,6 +29,9 @@ class Database: + # For table counts stop at this many rows: + count_limit = 10000 + def __init__( self, ds, @@ -376,7 +379,7 @@ async def table_counts(self, limit=10): 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] diff --git a/datasette/templates/database.html b/datasette/templates/database.html index f921bc2dbc..c6f3da99fc 100644 --- a/datasette/templates/database.html +++ b/datasette/templates/database.html @@ -60,7 +60,7 @@
{% for column in table.columns %}{{ column }}{% if not loop.last %}, {% endif %}{% endfor %}
-{% if table.count is none %}Many rows{% else %}{{ "{:,}".format(table.count) }} row{% if table.count == 1 %}{% else %}s{% endif %}{% endif %}
+{% 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 %}