diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2023-11-03 08:26:33 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-11-09 17:33:03 +0000 |
commit | 3a2c5a6fa2e0081c28d5f2f43e1d9a79d093ea37 (patch) | |
tree | f596b84a7295cd8421fcee447a10e2c082b94c72 /bitbake/lib/hashserv/sqlalchemy.py | |
parent | 8cfb94c06cdfe3e6f0ec1ce0154951108bc3df94 (diff) | |
download | poky-3a2c5a6fa2e0081c28d5f2f43e1d9a79d093ea37.tar.gz |
bitbake: hashserv: Add db-usage API
Adds an API to query the server for the usage of the database (e.g. how
many rows are present in each table)
(Bitbake rev: c9c1224447e147e0de92953bc85cea75670b898c)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/hashserv/sqlalchemy.py')
-rw-r--r-- | bitbake/lib/hashserv/sqlalchemy.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/bitbake/lib/hashserv/sqlalchemy.py b/bitbake/lib/hashserv/sqlalchemy.py index bfd8a8446e..818b51951b 100644 --- a/bitbake/lib/hashserv/sqlalchemy.py +++ b/bitbake/lib/hashserv/sqlalchemy.py | |||
@@ -27,6 +27,7 @@ from sqlalchemy import ( | |||
27 | and_, | 27 | and_, |
28 | delete, | 28 | delete, |
29 | update, | 29 | update, |
30 | func, | ||
30 | ) | 31 | ) |
31 | import sqlalchemy.engine | 32 | import sqlalchemy.engine |
32 | from sqlalchemy.orm import declarative_base | 33 | from sqlalchemy.orm import declarative_base |
@@ -401,3 +402,16 @@ class Database(object): | |||
401 | async with self.db.begin(): | 402 | async with self.db.begin(): |
402 | result = await self.db.execute(statement) | 403 | result = await self.db.execute(statement) |
403 | return result.rowcount != 0 | 404 | return result.rowcount != 0 |
405 | |||
406 | async def get_usage(self): | ||
407 | usage = {} | ||
408 | async with self.db.begin() as session: | ||
409 | for name, table in Base.metadata.tables.items(): | ||
410 | statement = select(func.count()).select_from(table) | ||
411 | self.logger.debug("%s", statement) | ||
412 | result = await self.db.execute(statement) | ||
413 | usage[name] = { | ||
414 | "rows": result.scalar(), | ||
415 | } | ||
416 | |||
417 | return usage | ||