This commit is contained in:
parent
4ca884f257
commit
9118ae9268
|
@ -25,15 +25,21 @@ Base = declarative_base()
|
||||||
# Перехватчики для журнала запросов SQLAlchemy
|
# Перехватчики для журнала запросов SQLAlchemy
|
||||||
@event.listens_for(Engine, 'before_cursor_execute')
|
@event.listens_for(Engine, 'before_cursor_execute')
|
||||||
def before_cursor_execute(conn, cursor, statement, parameters, context, executemany):
|
def before_cursor_execute(conn, cursor, statement, parameters, context, executemany):
|
||||||
conn.info.setdefault(f'query_start_time:{statement}', time.time())
|
query_id = id(cursor) # Уникальный идентификатор запроса
|
||||||
|
conn.info.setdefault(f'query_start_time:{query_id}', time.time())
|
||||||
|
|
||||||
@event.listens_for(Engine, 'after_cursor_execute')
|
@event.listens_for(Engine, 'after_cursor_execute')
|
||||||
def after_cursor_execute(conn, cursor, statement, parameters, context, executemany):
|
def after_cursor_execute(conn, cursor, statement, parameters, context, executemany):
|
||||||
total = time.time() - conn.info[f'query_start_time:{statement}']
|
query_id = id(cursor) # Уникальный идентификатор запроса
|
||||||
del conn.info[f'query_start_time:{statement}']
|
if f'query_start_time:{query_id}' in conn.info:
|
||||||
stars = '*' * math.floor(total*1000)
|
total = time.time() - conn.info.get(f'query_start_time:{query_id}', time.time())
|
||||||
if stars:
|
del conn.info[f'query_start_time:{query_id}']
|
||||||
logger.debug(f'\n{statement}\n {stars} {total*1000} s\n')
|
stars = '*' * math.floor(total*1000)
|
||||||
|
if stars:
|
||||||
|
logger.debug(f'\n{statement}\n {stars} {total*1000} s\n')
|
||||||
|
else:
|
||||||
|
logger.error(f"Не удалось найти информацию о времени начала запроса с идентификатором {query_id}.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def local_session(src=""):
|
def local_session(src=""):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user