summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/hashserv/sqlite.py
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2023-11-03 08:26:33 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-11-09 17:33:03 +0000
commit3a2c5a6fa2e0081c28d5f2f43e1d9a79d093ea37 (patch)
treef596b84a7295cd8421fcee447a10e2c082b94c72 /bitbake/lib/hashserv/sqlite.py
parent8cfb94c06cdfe3e6f0ec1ce0154951108bc3df94 (diff)
downloadpoky-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/sqlite.py')
-rw-r--r--bitbake/lib/hashserv/sqlite.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/bitbake/lib/hashserv/sqlite.py b/bitbake/lib/hashserv/sqlite.py
index 414ee8ffb8..dfdccbbaa0 100644
--- a/bitbake/lib/hashserv/sqlite.py
+++ b/bitbake/lib/hashserv/sqlite.py
@@ -120,6 +120,18 @@ class Database(object):
120 self.db = sqlite3.connect(self.dbname) 120 self.db = sqlite3.connect(self.dbname)
121 self.db.row_factory = sqlite3.Row 121 self.db.row_factory = sqlite3.Row
122 122
123 with closing(self.db.cursor()) as cursor:
124 cursor.execute("SELECT sqlite_version()")
125
126 version = []
127 for v in cursor.fetchone()[0].split("."):
128 try:
129 version.append(int(v))
130 except ValueError:
131 version.append(v)
132
133 self.sqlite_version = tuple(version)
134
123 async def __aenter__(self): 135 async def __aenter__(self):
124 return self 136 return self
125 137
@@ -362,3 +374,28 @@ class Database(object):
362 ) 374 )
363 self.db.commit() 375 self.db.commit()
364 return cursor.rowcount != 0 376 return cursor.rowcount != 0
377
378 async def get_usage(self):
379 usage = {}
380 with closing(self.db.cursor()) as cursor:
381 if self.sqlite_version >= (3, 33):
382 table_name = "sqlite_schema"
383 else:
384 table_name = "sqlite_master"
385
386 cursor.execute(
387 f"""
388 SELECT name FROM {table_name} WHERE type = 'table' AND name NOT LIKE 'sqlite_%'
389 """
390 )
391 for row in cursor.fetchall():
392 cursor.execute(
393 """
394 SELECT COUNT() FROM %s
395 """
396 % row["name"],
397 )
398 usage[row["name"]] = {
399 "rows": cursor.fetchone()[0],
400 }
401 return usage