Add DEBUG-level log for db row to native object conversion

This is now the bottleneck (by a large margin) for big history queries, so I'm leaving this log feature in to help diagnose users with a slow history page
This commit is contained in:
Greg Laabs
2017-07-29 17:40:04 -07:00
parent 8ac63fd70c
commit 356321ed2c

View File

@@ -58,10 +58,19 @@ def execute(qry):
for tryno in range(0, RETRIES): for tryno in range(0, RETRIES):
try: try:
return [ timer_start = time.perf_counter()
result = [
row for row in row for row in
(row.to_native() for row in qry) (row.to_native() for row in qry)
if row is not None] if row is not None]
if _LOGGER.isEnabledFor(logging.DEBUG):
elapsed = time.perf_counter() - timer_start
_LOGGER.debug('converting %d rows to native objects took %fs',
len(result),
elapsed)
return result
except SQLAlchemyError as err: except SQLAlchemyError as err:
_LOGGER.error("Error executing query: %s", err) _LOGGER.error("Error executing query: %s", err)