From: Michael Tremer Date: Thu, 3 Jul 2025 08:15:38 +0000 (+0000) Subject: database: For now, show the SQL queries again X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fb0d79c048c7528bdcd34894a617c279dd78586;p=pbs.git database: For now, show the SQL queries again Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/database.py b/src/buildservice/database.py index 962050ea..71f23430 100644 --- a/src/buildservice/database.py +++ b/src/buildservice/database.py @@ -36,34 +36,34 @@ from . import base # Setup logging log = logging.getLogger("pbs.database") -#@sqlalchemy.event.listens_for(sqlalchemy.Engine, "before_cursor_execute") -#def before_cursor_execute(conn, cursor, statement, parameters, context, executemany): -# now = time.time() -# -# # Create a queue to store start times -# try: -# q = conn.info["query_start_time"] -# except KeyError: -# q = conn.info["query_start_time"] = queue.LifoQueue() -# -# # Push the start time of the query -# q.put(now) -# -# # Log the statement -# log.debug("Start Query: %s %r", statement, parameters) -# -#@sqlalchemy.event.listens_for(sqlalchemy.Engine, "after_cursor_execute") -#def after_cursor_execute(conn, cursor, statement, parameters, context, executemany): -# time_end = time.time() -# -# # Fetch the latest start time -# time_start = conn.info["query_start_time"].get() -# -# # Compute the total time -# t = time_end - time_start -# -# # Log the total runtime -# log.debug("Query completed in %.02fms (%s row(s))", t * 1000, cursor.rowcount) +@sqlalchemy.event.listens_for(sqlalchemy.Engine, "before_cursor_execute") +def before_cursor_execute(conn, cursor, statement, parameters, context, executemany): + now = time.time() + + # Create a queue to store start times + try: + q = conn.info["query_start_time"] + except KeyError: + q = conn.info["query_start_time"] = queue.LifoQueue() + + # Push the start time of the query + q.put(now) + + # Log the statement + log.debug("Start Query: %s %r", statement, parameters) + +@sqlalchemy.event.listens_for(sqlalchemy.Engine, "after_cursor_execute") +def after_cursor_execute(conn, cursor, statement, parameters, context, executemany): + time_end = time.time() + + # Fetch the latest start time + time_start = conn.info["query_start_time"].get() + + # Compute the total time + t = time_end - time_start + + # Log the total runtime + log.debug("Query completed in %.02fms (%s row(s))", t * 1000, cursor.rowcount) class Base(sqlalchemy.ext.asyncio.AsyncAttrs, sqlalchemy.orm.DeclarativeBase): """