only print queries once

This commit is contained in:
Georges-Antoine Assi
2025-08-21 22:34:07 -04:00
parent 929a30946e
commit 8ed107336f
4 changed files with 9 additions and 11 deletions

View File

@@ -239,7 +239,7 @@ async def delete_firmware(
file_path = f"{firmware.file_path}/{firmware.file_name}"
await fs_firmware_handler.remove_file(file_path=file_path)
except FileNotFoundError:
error = f"Firmware file {hl(firmware.file_name)} not found for platform {hl(firmware.platform_slug)}"
error = f"Firmware file {hl(firmware.file_name)} not found for platform {hl(firmware.platform.slug)}"
log.error(error)
errors.append(error)
failed_items += 1

View File

@@ -1,3 +1,4 @@
import logging
import time
from config import DEV_SQL_ECHO
@@ -6,10 +7,13 @@ from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker
sync_engine = create_engine(
ConfigManager.get_db_engine(), pool_pre_ping=True, echo=DEV_SQL_ECHO
ConfigManager.get_db_engine(), pool_pre_ping=True, echo=False
)
sync_session = sessionmaker(bind=sync_engine, expire_on_commit=False)
# Disable SQLAlchemy logging as echo will print the queries
logging.getLogger("sqlalchemy.engine.Engine").handlers = [logging.NullHandler()]
if DEV_SQL_ECHO:
@@ -18,6 +22,7 @@ if DEV_SQL_ECHO:
conn, cursor, statement, parameters, context, executemany
):
context._query_start_time = time.time()
print("--------START--------")
print(f"SQL: {statement}")
print(f"Parameters: {parameters}")
@@ -25,6 +30,7 @@ if DEV_SQL_ECHO:
def after_cursor_execute(conn, cursor, statement, parameters, context, executemany):
total_time = time.time() - context._query_start_time
print(f"Execution time: {total_time:.4f} seconds")
print("--------END--------")
class DBBaseHandler: ...

View File

@@ -82,7 +82,7 @@ class PlaymatchHandler:
)
res.raise_for_status()
return res.json()
except (httpx.HTTPStatusError, httpx.ConnectError) as exc:
except (httpx.HTTPStatusError, httpx.ConnectError, httpx.ReadTimeout) as exc:
log.warning("Connection error: can't connect to Playmatch", exc_info=True)
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,

View File

@@ -51,14 +51,6 @@ class Firmware(BaseModel):
def platform_slug(self) -> str:
return self.platform.slug
@property
def platform_fs_slug(self) -> str:
return self.platform.fs_slug
@property
def platform_name(self) -> str:
return self.platform.name
@cached_property
def is_verified(self) -> bool:
cache_entry = sync_cache.hget(