mirror of
https://git.yoctoproject.org/poky
synced 2026-05-30 00:20:08 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
8cfb94c06c
commit
3a2c5a6fa2
@@ -27,6 +27,7 @@ from sqlalchemy import (
|
||||
and_,
|
||||
delete,
|
||||
update,
|
||||
func,
|
||||
)
|
||||
import sqlalchemy.engine
|
||||
from sqlalchemy.orm import declarative_base
|
||||
@@ -401,3 +402,16 @@ class Database(object):
|
||||
async with self.db.begin():
|
||||
result = await self.db.execute(statement)
|
||||
return result.rowcount != 0
|
||||
|
||||
async def get_usage(self):
|
||||
usage = {}
|
||||
async with self.db.begin() as session:
|
||||
for name, table in Base.metadata.tables.items():
|
||||
statement = select(func.count()).select_from(table)
|
||||
self.logger.debug("%s", statement)
|
||||
result = await self.db.execute(statement)
|
||||
usage[name] = {
|
||||
"rows": result.scalar(),
|
||||
}
|
||||
|
||||
return usage
|
||||
|
||||
Reference in New Issue
Block a user