mirror of
https://github.com/rommapp/romm.git
synced 2026-12-04 21:02:21 +01:00
log SQL queries and exec time in dev mode
This commit is contained in:
@@ -1,9 +1,30 @@
|
||||
import time
|
||||
|
||||
from config import DEV_MODE
|
||||
from config.config_manager import ConfigManager
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import create_engine, event
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
sync_engine = create_engine(ConfigManager.get_db_engine(), pool_pre_ping=True)
|
||||
sync_engine = create_engine(
|
||||
ConfigManager.get_db_engine(), pool_pre_ping=True, echo=DEV_MODE
|
||||
)
|
||||
sync_session = sessionmaker(bind=sync_engine, expire_on_commit=False)
|
||||
|
||||
|
||||
if DEV_MODE:
|
||||
|
||||
@event.listens_for(sync_engine, "before_cursor_execute")
|
||||
def before_cursor_execute(
|
||||
conn, cursor, statement, parameters, context, executemany
|
||||
):
|
||||
context._query_start_time = time.time()
|
||||
print(f"SQL: {statement}")
|
||||
print(f"Parameters: {parameters}")
|
||||
|
||||
@event.listens_for(sync_engine, "after_cursor_execute")
|
||||
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")
|
||||
|
||||
|
||||
class DBBaseHandler: ...
|
||||
|
||||
@@ -45,6 +45,21 @@ def with_simple(func):
|
||||
|
||||
|
||||
class DBRomsHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
@with_details
|
||||
def add_rom(self, rom: Rom, query: Query = None, session: Session = None) -> Rom:
|
||||
rom = session.merge(rom)
|
||||
session.flush()
|
||||
|
||||
return session.scalar(query.filter_by(id=rom.id).limit(1))
|
||||
|
||||
@begin_session
|
||||
@with_details
|
||||
def get_rom(
|
||||
self, id: int, *, query: Query = None, session: Session = None
|
||||
) -> Rom | None:
|
||||
return session.scalar(query.filter_by(id=id).limit(1))
|
||||
|
||||
def filter_by_platform_id(self, query: Query, platform_id: int):
|
||||
return query.filter(Rom.platform_id == platform_id)
|
||||
|
||||
@@ -313,21 +328,6 @@ class DBRomsHandler(DBBaseHandler):
|
||||
|
||||
return query
|
||||
|
||||
@begin_session
|
||||
@with_details
|
||||
def add_rom(self, rom: Rom, query: Query = None, session: Session = None) -> Rom:
|
||||
rom = session.merge(rom)
|
||||
session.flush()
|
||||
|
||||
return session.scalar(query.filter_by(id=rom.id).limit(1))
|
||||
|
||||
@begin_session
|
||||
@with_details
|
||||
def get_rom(
|
||||
self, id: int, *, query: Query = None, session: Session = None
|
||||
) -> Rom | None:
|
||||
return session.scalar(query.filter_by(id=id).limit(1))
|
||||
|
||||
@with_simple
|
||||
def get_roms_query(
|
||||
self,
|
||||
|
||||
@@ -25,7 +25,7 @@ const { currentView } = storeToRefs(galleryViewStore);
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
<v-row class="h-100" v-if="currentView == 2" no-gutters>
|
||||
<v-row class="h-100 mr-14" v-if="currentView == 2" no-gutters>
|
||||
<v-col class="h-100 pt-4 pb-2">
|
||||
<v-skeleton-loader
|
||||
class="mx-2"
|
||||
|
||||
@@ -322,7 +322,7 @@ onBeforeUnmount(() => {
|
||||
</v-row>
|
||||
|
||||
<!-- Gallery list view -->
|
||||
<v-row class="h-100" v-if="currentView == 2" no-gutters>
|
||||
<v-row class="h-100 mr-14" v-if="currentView == 2" no-gutters>
|
||||
<v-col class="h-100 pt-4 pb-2">
|
||||
<game-data-table show-platform-icon class="h-100 mx-2" />
|
||||
</v-col>
|
||||
|
||||
Reference in New Issue
Block a user