mirror of
https://github.com/rommapp/romm.git
synced 2026-12-06 15:54:45 +01:00
refactor stats and user handlers
This commit is contained in:
1 parent
b4d623c617
commit
0af3ffb86f
27 files changed
+467
-486
No files matched your search
@@ -0,0 +1,42 @@
|
||||
from decorators.database import begin_session
|
||||
from handler.db_handler import DBHandler
|
||||
from models import Platform, Rom, Save, Screenshot, State
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
class DBStatsHandler(DBHandler):
|
||||
@begin_session
|
||||
def get_platforms_count(self, session: Session = None):
|
||||
# Only count platforms with more then 0 roms
|
||||
return session.scalar(
|
||||
select(func.count())
|
||||
.select_from(Platform)
|
||||
.where(
|
||||
select(func.count())
|
||||
.select_from(Rom)
|
||||
.filter_by(platform_id=Platform.id)
|
||||
.as_scalar()
|
||||
> 0
|
||||
)
|
||||
)
|
||||
|
||||
@begin_session
|
||||
def get_roms_count(self, session: Session = None) -> int:
|
||||
return session.scalar(select(func.count()).select_from(Rom))
|
||||
|
||||
@begin_session
|
||||
def get_saves_count(self, session: Session = None) -> int:
|
||||
return session.scalar(select(func.count()).select_from(Save))
|
||||
|
||||
@begin_session
|
||||
def get_states_count(self, session: Session = None) -> int:
|
||||
return session.scalar(select(func.count()).select_from(State))
|
||||
|
||||
@begin_session
|
||||
def get_screenshots_count(self, session: Session = None) -> int:
|
||||
return session.scalar(select(func.count()).select_from(Screenshot))
|
||||
|
||||
@begin_session
|
||||
def get_total_filesize(self, session: Session = None) -> int:
|
||||
return 0
|
||||
Reference in new issue
Block a user