This commit is contained in:
parent
f75eb13971
commit
2cfcab744e
|
@ -194,7 +194,7 @@ async def get_author_by_user_id(user_id: str):
|
|||
redis_key = f"user:{user_id}:author"
|
||||
res = await redis.execute("HGET", redis_key)
|
||||
if isinstance(res, dict) and res.get("id"):
|
||||
logger.debug(f'got cached author: {res}')
|
||||
logger.debug(f"got cached author: {res}")
|
||||
return res
|
||||
|
||||
logger.info(f"getting author id for {user_id}")
|
||||
|
|
|
@ -23,21 +23,24 @@ Base = declarative_base()
|
|||
|
||||
|
||||
# Перехватчики для журнала запросов 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):
|
||||
query_id = id(cursor) # Уникальный идентификатор запроса
|
||||
conn.info.setdefault(f'query_start_time:{query_id}', time.time())
|
||||
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):
|
||||
query_id = id(cursor) # Уникальный идентификатор запроса
|
||||
if f'query_start_time:{query_id}' in conn.info:
|
||||
total = time.time() - conn.info.get(f'query_start_time:{query_id}', time.time())
|
||||
del conn.info[f'query_start_time:{query_id}']
|
||||
stars = '*' * math.floor(total*1000)
|
||||
if stars:
|
||||
logger.debug(f'\n{statement}\n {stars} {total*1000} s\n')
|
||||
|
||||
if f"query_start_time:{query_id}" in conn.info:
|
||||
total = time.time() - conn.info.get(f"query_start_time:{query_id}", time.time())
|
||||
try:
|
||||
del conn.info[f"query_start_time:{query_id}"]
|
||||
stars = "*" * math.floor(total * 1000)
|
||||
if stars:
|
||||
logger.debug(f"\n{statement}\n {stars} {total*1000} s\n")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def local_session(src=""):
|
||||
|
|
Loading…
Reference in New Issue
Block a user