mirror of
https://github.com/simonw/datasette.git
synced 2026-05-29 21:26:59 +02:00
datasette inspect now counts 10,000+ tables correctly (#2752)
Closes #2712 Refs https://github.com/simonw/datasette/pull/2721#issuecomment-4568966383
This commit is contained in:
parent
74324cb849
commit
6a998610ee
3 changed files with 22 additions and 4 deletions
|
|
@ -21,6 +21,7 @@ from .app import (
|
|||
SQLITE_LIMIT_ATTACHED,
|
||||
pm,
|
||||
)
|
||||
from .inspect import inspect_tables
|
||||
from .utils import (
|
||||
LoadExtension,
|
||||
StartupError,
|
||||
|
|
@ -154,14 +155,14 @@ async def inspect_(files, sqlite_extensions):
|
|||
app = Datasette([], immutables=files, sqlite_extensions=sqlite_extensions)
|
||||
data = {}
|
||||
for name, database in app.databases.items():
|
||||
counts = await database.table_counts(limit=3600 * 1000)
|
||||
tables = await database.execute_fn(lambda conn: inspect_tables(conn, {}))
|
||||
data[name] = {
|
||||
"hash": database.hash,
|
||||
"size": database.size,
|
||||
"file": database.path,
|
||||
"tables": {
|
||||
table_name: {"count": table_count}
|
||||
for table_name, table_count in counts.items()
|
||||
table_name: {"count": table["count"]}
|
||||
for table_name, table in tables.items()
|
||||
},
|
||||
}
|
||||
return data
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ Bug fixes
|
|||
~~~~~~~~~
|
||||
|
||||
- Fixed a bug where visiting ``/<database>/-/query`` without a ``?sql=`` parameter returned a 500 error. (:issue:`2743`)
|
||||
- The ``datasette inspect`` command now correctly records row counts for tables with more than 10,000 rows. (:issue:`2712`)
|
||||
|
||||
.. _v1_0_a30:
|
||||
|
||||
|
|
|
|||
|
|
@ -35,12 +35,28 @@ def test_inspect_cli(app_client):
|
|||
assert expected_count == database["tables"][table_name]["count"]
|
||||
|
||||
|
||||
def test_inspect_cli_counts_all_rows(tmp_path):
|
||||
db_path = tmp_path / "big.db"
|
||||
conn = sqlite3.connect(db_path)
|
||||
with conn:
|
||||
conn.execute("create table t (id integer primary key)")
|
||||
conn.executemany("insert into t (id) values (?)", ((i,) for i in range(10002)))
|
||||
conn.close()
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ["inspect", str(db_path)])
|
||||
assert result.exit_code == 0, result.output
|
||||
data = json.loads(result.output)
|
||||
|
||||
assert data["big"]["tables"]["t"]["count"] == 10002
|
||||
|
||||
|
||||
def test_inspect_cli_writes_to_file(app_client):
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli, ["inspect", "fixtures.db", "--inspect-file", "foo.json"]
|
||||
)
|
||||
assert 0 == result.exit_code, result.output
|
||||
assert result.exit_code == 0, result.output
|
||||
with open("foo.json") as fp:
|
||||
data = json.load(fp)
|
||||
assert ["fixtures"] == list(data.keys())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue