Skip to content

Commit

Permalink
Don't count rows on homepage for DBs > 100MB (#688)
Browse files Browse the repository at this point in the history
Closes #649.
  • Loading branch information
simonw committed Feb 29, 2020
1 parent 0f8e91c commit 7f5a330
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions datasette/views/index.py
Expand Up @@ -11,8 +11,8 @@
# Truncate table list on homepage at:
TRUNCATE_AT = 5

# Only attempt counts if less than this many tables:
COUNT_TABLE_LIMIT = 30
# Only attempt counts if database less than this size in bytes:
COUNT_DB_SIZE_LIMIT = 100 * 1024 * 1024


class IndexView(BaseView):
Expand All @@ -29,7 +29,7 @@ async def get(self, request, as_format):
views = await db.view_names()
# Perform counts only for immutable or DBS with <= COUNT_TABLE_LIMIT tables
table_counts = {}
if not db.is_mutable or len(table_names) <= COUNT_TABLE_LIMIT:
if not db.is_mutable or db.size < COUNT_DB_SIZE_LIMIT:
table_counts = await db.table_counts(10)
# If any of these are None it means at least one timed out - ignore them all
if any(v is None for v in table_counts.values()):
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures.py
Expand Up @@ -229,7 +229,7 @@ def app_client_with_cors():

@pytest.fixture(scope="session")
def app_client_immutable_and_inspect_file():
inspect_data = {'fixtures': {'tables': {'sortable': {'count': 100}}}}
inspect_data = {"fixtures": {"tables": {"sortable": {"count": 100}}}}
yield from make_app_client(is_immutable=True, inspect_data=inspect_data)


Expand Down

0 comments on commit 7f5a330

Please sign in to comment.