mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 02:24:09 +01:00
chore(mypy): require coded ignores and flag stale ones, type protected_route (#4794)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
[mypy]
|
||||
check_untyped_defs = True
|
||||
warn_unused_ignores = True
|
||||
warn_redundant_casts = True
|
||||
disable_error_code = import-untyped
|
||||
enable_error_code = ignore-without-code
|
||||
# INI configs take a regex here, not a TOML-style list.
|
||||
exclude = (?x)(^|/)alembic/
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ async def auth_middleware(
|
||||
|
||||
Reference: https://api-docs.retroachievements.org/getting-started.html#quick-start-http-requests
|
||||
"""
|
||||
req.url = req.url.update_query({"y": RETROACHIEVEMENTS_API_KEY}) # type: ignore
|
||||
req.url = req.url.update_query({"y": RETROACHIEVEMENTS_API_KEY}) # type: ignore[dict-item]
|
||||
return await handler(req)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import functools
|
||||
import inspect
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from authlib.integrations.starlette_client import OAuth
|
||||
@@ -135,11 +136,11 @@ def _requires_scopes(scopes: list[Scope]):
|
||||
|
||||
|
||||
def protected_route(
|
||||
method: Any,
|
||||
method: Callable[..., Callable[[DecoratedCallable], DecoratedCallable]],
|
||||
path: str,
|
||||
scopes: list[Scope] | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
**kwargs: Any,
|
||||
) -> Callable[[DecoratedCallable], DecoratedCallable]:
|
||||
def decorator(func: DecoratedCallable) -> DecoratedCallable:
|
||||
fn = _requires_scopes(scopes or [])(func)
|
||||
return method(
|
||||
|
||||
@@ -41,14 +41,14 @@ class PlatformSchema(BaseModel):
|
||||
is_identified: bool
|
||||
missing_from_fs: bool
|
||||
|
||||
@computed_field # type: ignore
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def display_name(self) -> str:
|
||||
return self.custom_name or self.name
|
||||
|
||||
# Counts every row like `rom_count` does; callers wanting only usable
|
||||
# BIOS filter the `firmware` list that ships alongside it.
|
||||
@computed_field # type: ignore
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def firmware_count(self) -> int:
|
||||
return len(self.firmware)
|
||||
|
||||
@@ -488,7 +488,7 @@ class SiblingRomSchema(BaseModel):
|
||||
fs_name_no_ext: str
|
||||
is_main_sibling: bool
|
||||
|
||||
@computed_field # type: ignore
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def sort_comparator(self) -> str:
|
||||
return (
|
||||
|
||||
@@ -324,7 +324,8 @@ async def rename_asset[AssetT: (Save, State)](asset: AssetT, file_name: str) ->
|
||||
thumbnail.id, {"file_name": thumbnail_name}, session=session
|
||||
)
|
||||
if isinstance(asset, Save):
|
||||
return cast(
|
||||
# Redundant only in mypy's AssetT=Save pass; the State pass needs it.
|
||||
return cast( # type: ignore[redundant-cast]
|
||||
AssetT,
|
||||
db_save_handler.update_save(
|
||||
asset.id, {"file_name": new_name}, touch=False, session=session
|
||||
|
||||
@@ -6,7 +6,7 @@ import functools
|
||||
import http.cookies
|
||||
import secrets
|
||||
from re import Pattern
|
||||
from typing import Optional, cast
|
||||
from typing import Optional
|
||||
|
||||
from itsdangerous import BadSignature
|
||||
from itsdangerous.url_safe import URLSafeSerializer
|
||||
@@ -150,7 +150,7 @@ class CSRFMiddleware:
|
||||
|
||||
def _generate_csrf_token(self, user_id: int | None = None) -> str:
|
||||
obj = {"token": secrets.token_urlsafe(128), "user_id": user_id}
|
||||
return cast(str, self.serializer.dumps(obj))
|
||||
return self.serializer.dumps(obj)
|
||||
|
||||
def _csrf_cookie_has_user(
|
||||
self, csrf_cookie: str | None, user_id: int | None
|
||||
|
||||
@@ -57,7 +57,7 @@ class DBAuditEventsHandler(DBBaseHandler):
|
||||
def add_events(
|
||||
self,
|
||||
events: Sequence[AuditEvent],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.add_all(events)
|
||||
|
||||
@@ -67,7 +67,7 @@ class DBAuditEventsHandler(DBBaseHandler):
|
||||
filters: AuditEventFilters,
|
||||
limit: int,
|
||||
offset: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[list[tuple[AuditEvent, str | None]], int, int | None]:
|
||||
"""A page of events, newest first, each with its device's name, the total,
|
||||
and the highest id among the matches for later pages to be pinned to."""
|
||||
@@ -143,7 +143,7 @@ class DBAuditEventsHandler(DBBaseHandler):
|
||||
self,
|
||||
cutoff: datetime,
|
||||
batch_size: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Delete up to `batch_size` of the oldest events from before `cutoff`."""
|
||||
# Ids first: MySQL refuses a LIMIT inside an IN subquery.
|
||||
|
||||
@@ -18,7 +18,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
def add_token(
|
||||
self,
|
||||
token: ClientToken,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> ClientToken:
|
||||
return session.merge(token)
|
||||
|
||||
@@ -26,7 +26,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
def get_token_by_hash(
|
||||
self,
|
||||
hashed_token: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> ClientToken | None:
|
||||
return session.scalar(
|
||||
select(ClientToken).where(ClientToken.hashed_token == hashed_token)
|
||||
@@ -36,7 +36,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
def get_tokens_by_user(
|
||||
self,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[ClientToken]:
|
||||
return session.scalars(
|
||||
select(ClientToken)
|
||||
@@ -47,7 +47,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def get_all_tokens(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[ClientToken]:
|
||||
return (
|
||||
session.scalars(
|
||||
@@ -64,7 +64,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
self,
|
||||
token_id: int,
|
||||
user_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
stmt = delete(ClientToken).where(ClientToken.id == token_id)
|
||||
if user_id is not None:
|
||||
@@ -77,7 +77,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
def update_last_used(
|
||||
self,
|
||||
token_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
now = datetime.now(timezone.utc)
|
||||
token = session.get(ClientToken, token_id)
|
||||
@@ -103,7 +103,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
token_id: int,
|
||||
new_hash: str,
|
||||
user_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> ClientToken | None:
|
||||
stmt = (
|
||||
update(ClientToken)
|
||||
@@ -125,7 +125,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
def count_tokens_by_user(
|
||||
self,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
return (
|
||||
session.scalar(
|
||||
@@ -141,7 +141,7 @@ class DBClientTokensHandler(DBBaseHandler):
|
||||
self,
|
||||
token_id: int,
|
||||
user_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> ClientToken | None:
|
||||
stmt = select(ClientToken).where(ClientToken.id == token_id)
|
||||
if user_id is not None:
|
||||
|
||||
@@ -73,8 +73,8 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def add_collection(
|
||||
self,
|
||||
collection: Collection,
|
||||
query: Select[tuple[Collection]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Collection]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Collection:
|
||||
collection = session.merge(collection)
|
||||
session.flush()
|
||||
@@ -86,8 +86,8 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def get_collection(
|
||||
self,
|
||||
id: int,
|
||||
query: Select[tuple[Collection]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Collection]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Collection | None:
|
||||
return session.scalar(query.filter_by(id=id).limit(1))
|
||||
|
||||
@@ -97,8 +97,8 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
name: str,
|
||||
user_id: int,
|
||||
query: Select[tuple[Collection]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Collection]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Collection | None:
|
||||
return session.scalar(query.filter_by(name=name, user_id=user_id).limit(1))
|
||||
|
||||
@@ -107,8 +107,8 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def get_favorite_collection(
|
||||
self,
|
||||
user_id: int,
|
||||
query: Select[tuple[Collection]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Collection]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Collection | None:
|
||||
return session.scalar(
|
||||
query.filter_by(is_favorite=True, user_id=user_id).limit(1)
|
||||
@@ -129,7 +129,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def get_collections(
|
||||
self,
|
||||
updated_after: datetime | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Collection]:
|
||||
query = self._collections_query(updated_after=updated_after)
|
||||
return session.scalars(query.options(*_roms_load_options())).unique().all()
|
||||
@@ -138,7 +138,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def get_collection_ids(
|
||||
self,
|
||||
updated_after: datetime | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[Row[tuple[int, int, bool]]]:
|
||||
"""Id, owner and visibility only, so neither eager load fires."""
|
||||
query = self._collections_query(updated_after=updated_after)
|
||||
@@ -157,8 +157,8 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
id: int,
|
||||
data: dict,
|
||||
rom_ids: list[int] | None = None,
|
||||
query: Select[tuple[Collection]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Collection]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Collection:
|
||||
session.execute(
|
||||
update(Collection)
|
||||
@@ -196,8 +196,8 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
rom_ids: list[int],
|
||||
query: Select[tuple[Collection]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Collection]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Collection:
|
||||
if rom_ids:
|
||||
valid_rom_ids = set(
|
||||
@@ -239,8 +239,8 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
rom_ids: list[int],
|
||||
query: Select[tuple[Collection]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Collection]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Collection:
|
||||
if rom_ids:
|
||||
result = session.execute(
|
||||
@@ -263,7 +263,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def delete_collection(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(Collection)
|
||||
@@ -332,7 +332,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def get_virtual_collection(
|
||||
self,
|
||||
id: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> VirtualCollection | None:
|
||||
name, type = VirtualCollection.from_id(id)
|
||||
collection = session.scalar(
|
||||
@@ -349,7 +349,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
type: str,
|
||||
limit: int | None = None,
|
||||
only_fields: Sequence[QueryableAttribute] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[VirtualCollection]:
|
||||
query = (
|
||||
select(VirtualCollection)
|
||||
@@ -380,7 +380,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def add_smart_collection(
|
||||
self,
|
||||
smart_collection: SmartCollection,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SmartCollection:
|
||||
smart_collection = session.merge(smart_collection)
|
||||
session.flush()
|
||||
@@ -393,7 +393,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def get_smart_collection(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SmartCollection | None:
|
||||
return session.scalar(select(SmartCollection).filter_by(id=id).limit(1))
|
||||
|
||||
@@ -402,7 +402,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
name: str,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SmartCollection | None:
|
||||
return session.scalar(
|
||||
select(SmartCollection).filter_by(name=name, user_id=user_id).limit(1)
|
||||
@@ -431,7 +431,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int | None = None,
|
||||
updated_after: datetime | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[SmartCollection]:
|
||||
query = self._smart_collections_query(
|
||||
user_id=user_id, updated_after=updated_after
|
||||
@@ -443,7 +443,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int | None = None,
|
||||
updated_after: datetime | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
"""Ids only, so no `SmartCollection` is built and no eager user join fires."""
|
||||
query = self._smart_collections_query(
|
||||
@@ -456,7 +456,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[SmartCollection]:
|
||||
# Membership is a cached JSON array of rom ids on the collection, so
|
||||
# push containment + visibility into SQL rather than loading every
|
||||
@@ -491,7 +491,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict[str, Any],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SmartCollection:
|
||||
session.execute(
|
||||
update(SmartCollection)
|
||||
@@ -506,7 +506,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def delete_smart_collection(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(SmartCollection)
|
||||
@@ -553,7 +553,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
smart_collection: SmartCollection,
|
||||
user_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Row[tuple[int, str | None, str | None]]]:
|
||||
"""Every member's id and cover paths, in the collection's own order.
|
||||
|
||||
@@ -583,7 +583,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
def refresh_smart_collection(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SmartCollection | None:
|
||||
"""Recompute a smart collection's cached membership columns.
|
||||
|
||||
@@ -640,7 +640,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def refresh_smart_collections(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Refresh every smart collection, e.g. once the library has changed."""
|
||||
ids = session.scalars(select(SmartCollection.id)).all()
|
||||
@@ -654,7 +654,7 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_ids: Sequence[int],
|
||||
membership_only: bool = False,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
):
|
||||
"""Refresh the collections a handful of changed ROMs touch.
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class DBContainerAdoptionsHandler(DBBaseHandler):
|
||||
def get_adoption(
|
||||
self,
|
||||
container_key: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> StreamingContainerAdoption | None:
|
||||
return session.scalar(
|
||||
select(StreamingContainerAdoption).filter_by(container_key=container_key)
|
||||
@@ -25,7 +25,7 @@ class DBContainerAdoptionsHandler(DBBaseHandler):
|
||||
container_key: str,
|
||||
outcome: AdoptionOutcome,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> StreamingContainerAdoption | None:
|
||||
"""Returns None when another claim recorded the decision first. The
|
||||
unique constraint is the arbiter, not the earlier read."""
|
||||
|
||||
@@ -50,7 +50,7 @@ class DBDeletedAssetsHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
slot: str,
|
||||
content_hash: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> DeletedAsset:
|
||||
record = DeletedAsset(
|
||||
user_id=user_id,
|
||||
@@ -69,7 +69,7 @@ class DBDeletedAssetsHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
slot: str,
|
||||
content_hash: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> DeletedAsset | None:
|
||||
"""Add this version to the slot's record, or None when it has none yet."""
|
||||
record = session.scalar(
|
||||
@@ -91,7 +91,7 @@ class DBDeletedAssetsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
rom_ids: Collection[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[DeletedAsset]:
|
||||
"""Every slot of these ROMs this user emptied."""
|
||||
if not rom_ids:
|
||||
|
||||
@@ -17,7 +17,7 @@ class DBDeviceSaveSyncHandler(DBBaseHandler):
|
||||
self,
|
||||
device_id: str,
|
||||
save_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> DeviceSaveSync | None:
|
||||
return session.scalar(
|
||||
select(DeviceSaveSync)
|
||||
@@ -30,7 +30,7 @@ class DBDeviceSaveSyncHandler(DBBaseHandler):
|
||||
self,
|
||||
device_id: str,
|
||||
save_ids: list[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[DeviceSaveSync]:
|
||||
if not save_ids:
|
||||
return []
|
||||
@@ -45,7 +45,7 @@ class DBDeviceSaveSyncHandler(DBBaseHandler):
|
||||
def get_syncs_for_saves(
|
||||
self,
|
||||
save_ids: list[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict[int, list[tuple[DeviceSaveSync, str | None]]]:
|
||||
"""Fetch every device sync row for the given saves, grouped by save id.
|
||||
|
||||
@@ -72,7 +72,7 @@ class DBDeviceSaveSyncHandler(DBBaseHandler):
|
||||
device_id: str,
|
||||
save_id: int,
|
||||
synced_at: datetime | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> DeviceSaveSync:
|
||||
now = synced_at or datetime.now(timezone.utc)
|
||||
existing = session.scalar(
|
||||
@@ -110,7 +110,7 @@ class DBDeviceSaveSyncHandler(DBBaseHandler):
|
||||
device_id: str,
|
||||
save_id: int,
|
||||
untracked: bool,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> DeviceSaveSync | None:
|
||||
existing = session.scalar(
|
||||
select(DeviceSaveSync)
|
||||
@@ -146,7 +146,7 @@ class DBDeviceSaveSyncHandler(DBBaseHandler):
|
||||
def delete_syncs_for_device(
|
||||
self,
|
||||
device_id: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(DeviceSaveSync)
|
||||
|
||||
@@ -18,7 +18,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
def add_device(
|
||||
self,
|
||||
device: Device,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Device:
|
||||
return session.merge(device)
|
||||
|
||||
@@ -27,7 +27,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
self,
|
||||
device_id: str,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Device | None:
|
||||
return session.scalar(
|
||||
select(Device).filter_by(id=device_id, user_id=user_id).limit(1)
|
||||
@@ -41,7 +41,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
hostname: str | None = None,
|
||||
ip_address: str | None = None,
|
||||
platform: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Device | None:
|
||||
if mac_address:
|
||||
device = session.scalar(
|
||||
@@ -72,7 +72,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
def get_device_by_id(
|
||||
self,
|
||||
device_id: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Device | None:
|
||||
"""Get a device by ID without user filtering (for server-side operations)."""
|
||||
return session.scalar(select(Device).filter_by(id=device_id).limit(1))
|
||||
@@ -82,7 +82,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
client_device_identifier: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Device | None:
|
||||
"""Find a device by its client-supplied stable identifier, scoped to a user."""
|
||||
if not client_device_identifier:
|
||||
@@ -100,7 +100,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
def get_devices(
|
||||
self,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Device]:
|
||||
return session.scalars(select(Device).filter_by(user_id=user_id)).all()
|
||||
|
||||
@@ -108,7 +108,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
def get_all_devices_by_sync_mode(
|
||||
self,
|
||||
sync_mode: SyncMode,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Device]:
|
||||
"""Get all devices with a specific sync mode (across all users)."""
|
||||
return session.scalars(select(Device).filter_by(sync_mode=sync_mode)).all()
|
||||
@@ -119,7 +119,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
device_id: str,
|
||||
user_id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Device | None:
|
||||
session.execute(
|
||||
update(Device)
|
||||
@@ -136,7 +136,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
self,
|
||||
device_id: str,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
update(Device)
|
||||
@@ -149,7 +149,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
def update_last_seen_debounced(
|
||||
self,
|
||||
device_id: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
"""Bump last_seen on the device, skipping if updated within the debounce window.
|
||||
|
||||
@@ -176,7 +176,7 @@ class DBDevicesHandler(DBBaseHandler):
|
||||
self,
|
||||
device_id: str,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(Device)
|
||||
|
||||
@@ -14,7 +14,7 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
def add_firmware(
|
||||
self,
|
||||
firmware: Firmware,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Firmware:
|
||||
return session.merge(firmware)
|
||||
|
||||
@@ -23,7 +23,7 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Firmware | None:
|
||||
return session.scalar(select(Firmware).filter_by(id=id).limit(1))
|
||||
|
||||
@@ -56,7 +56,7 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
platform_ids: Sequence[int] | None = None,
|
||||
missing: bool | None = None,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Firmware]:
|
||||
query = self._firmware_query(
|
||||
platform_ids=platform_ids,
|
||||
@@ -74,7 +74,7 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
platform_ids: Sequence[int] | None = None,
|
||||
missing: bool | None = None,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
"""Ids only, so no `Firmware` is built and no eager platform join fires."""
|
||||
query = self._firmware_query(
|
||||
@@ -89,7 +89,7 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
self,
|
||||
platform_id: int,
|
||||
file_name: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
):
|
||||
return session.scalar(
|
||||
select(Firmware)
|
||||
@@ -102,7 +102,7 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Firmware:
|
||||
session.execute(
|
||||
update(Firmware)
|
||||
@@ -116,7 +116,7 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
def delete_firmware(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(Firmware)
|
||||
@@ -129,7 +129,7 @@ class DBFirmwareHandler(DBBaseHandler):
|
||||
self,
|
||||
platform_id: int,
|
||||
fs_firmwares_to_keep: list[str],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Firmware]:
|
||||
missing_firmware = (
|
||||
session.scalars(
|
||||
|
||||
@@ -16,7 +16,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
def add_card(
|
||||
self,
|
||||
card: MemoryCard,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MemoryCard:
|
||||
return session.merge(card)
|
||||
|
||||
@@ -25,7 +25,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MemoryCard | None:
|
||||
"""Owner-scoped fetch, for mutations the caller must own (rename,
|
||||
share, delete)."""
|
||||
@@ -37,7 +37,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
def get_card_by_id(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MemoryCard | None:
|
||||
"""Unscoped fetch, for reads that may cross ownership (a public card's
|
||||
detail or version list) and for lookups by an id already resolved to
|
||||
@@ -50,7 +50,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
emulator: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[MemoryCard]:
|
||||
"""A user's own cards, optionally filtered to one emulator (the pick
|
||||
list shown at session claim)."""
|
||||
@@ -64,7 +64,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
self,
|
||||
emulator: str,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[MemoryCard]:
|
||||
"""Cards for an emulator visible to the requesting user: their own plus
|
||||
other users' public ones. Browsing only, since another user's card is
|
||||
@@ -83,7 +83,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MemoryCard | None:
|
||||
"""Returns None when the row was deleted concurrently."""
|
||||
session.execute(
|
||||
@@ -98,7 +98,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
def delete_card(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[str]:
|
||||
"""Delete a card and return the paths of the version archives that went
|
||||
with it. The listing shares the delete's transaction and locks the rows,
|
||||
@@ -127,7 +127,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
def add_version(
|
||||
self,
|
||||
version: MemoryCardVersion,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MemoryCardVersion:
|
||||
return session.merge(version)
|
||||
|
||||
@@ -135,7 +135,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
def get_latest_version(
|
||||
self,
|
||||
card_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MemoryCardVersion | None:
|
||||
"""Newest snapshot of a card, used to hydrate a container at claim.
|
||||
|
||||
@@ -155,7 +155,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
self,
|
||||
card_id: int,
|
||||
content_hash: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MemoryCardVersion | None:
|
||||
"""Dedup lookup on evacuate: skip storing a snapshot identical to one
|
||||
already held for this card."""
|
||||
@@ -169,7 +169,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
def get_version_by_id(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MemoryCardVersion | None:
|
||||
"""Unscoped fetch, for the content-download route."""
|
||||
return session.get(MemoryCardVersion, id)
|
||||
@@ -178,7 +178,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
def get_versions(
|
||||
self,
|
||||
card_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[MemoryCardVersion]:
|
||||
"""A card's snapshot history, newest first."""
|
||||
return session.scalars(
|
||||
@@ -192,7 +192,7 @@ class DBMemoryCardsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
missing: bool,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
"""Record whether a version's archive is still on disk, so the history
|
||||
can say a snapshot is gone instead of offering a download that 404s."""
|
||||
|
||||
@@ -16,7 +16,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
def add_playlist(
|
||||
self,
|
||||
playlist: MusicPlaylist,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MusicPlaylist:
|
||||
playlist = session.merge(playlist)
|
||||
session.flush()
|
||||
@@ -29,7 +29,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
def get_playlist(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MusicPlaylist | None:
|
||||
return session.scalar(select(MusicPlaylist).filter_by(id=id).limit(1))
|
||||
|
||||
@@ -38,7 +38,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
self,
|
||||
name: str,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MusicPlaylist | None:
|
||||
return session.scalar(
|
||||
select(MusicPlaylist).filter_by(name=name, user_id=user_id).limit(1)
|
||||
@@ -48,7 +48,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
def get_playlists(
|
||||
self,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[MusicPlaylist]:
|
||||
"""The user's own playlists plus other users' public ones."""
|
||||
return (
|
||||
@@ -71,7 +71,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> MusicPlaylist:
|
||||
session.execute(
|
||||
update(MusicPlaylist)
|
||||
@@ -86,7 +86,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
def delete_playlist(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(MusicPlaylist)
|
||||
@@ -98,7 +98,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
def get_playlist_track_counts(
|
||||
self,
|
||||
playlist_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict[int, int]:
|
||||
"""Stored entry counts per playlist, before any visibility filtering."""
|
||||
if not playlist_ids:
|
||||
@@ -114,7 +114,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
def get_playlist_entries(
|
||||
self,
|
||||
playlist_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[MusicPlaylistTrack]:
|
||||
return session.scalars(
|
||||
select(MusicPlaylistTrack)
|
||||
@@ -127,7 +127,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
self,
|
||||
playlist_id: int,
|
||||
rom_file_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
candidates = list(dict.fromkeys(rom_file_ids))
|
||||
if not candidates:
|
||||
@@ -175,7 +175,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
self,
|
||||
playlist_id: int,
|
||||
rom_file_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
if not rom_file_ids:
|
||||
return 0
|
||||
@@ -194,7 +194,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
self,
|
||||
playlist_id: int,
|
||||
ordered_entry_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
"""Rewrite positions to match ordered_entry_ids; entries not listed keep
|
||||
their relative order after the listed ones."""
|
||||
@@ -217,7 +217,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
rom_file_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
candidates = list(dict.fromkeys(rom_file_ids))
|
||||
if not candidates:
|
||||
@@ -252,7 +252,7 @@ class DBMusicPlaylistsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
rom_file_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
if not rom_file_ids:
|
||||
return 0
|
||||
|
||||
@@ -21,7 +21,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
def get_channels(
|
||||
self,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[NotificationChannel]:
|
||||
return session.scalars(
|
||||
select(NotificationChannel)
|
||||
@@ -34,7 +34,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
self,
|
||||
channel_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> NotificationChannel | None:
|
||||
return session.scalar(
|
||||
select(NotificationChannel).where(
|
||||
@@ -47,7 +47,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
def get_channel_for_delivery(
|
||||
self,
|
||||
channel_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[NotificationChannel, str] | None:
|
||||
"""The channel and its owner's role, as of now."""
|
||||
row = session.execute(
|
||||
@@ -64,7 +64,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
def get_deliverable_channels(
|
||||
self,
|
||||
user_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[NotificationChannel]:
|
||||
"""The users' channels that are on and, for an email address, confirmed."""
|
||||
return session.scalars(
|
||||
@@ -80,7 +80,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
self,
|
||||
channel: NotificationChannel,
|
||||
limit: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> NotificationChannel | None:
|
||||
"""Add the channel unless its user already has `limit`; None if they do."""
|
||||
# Locking the user's row makes that user's concurrent adds count in turn.
|
||||
@@ -104,7 +104,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
channel_id: int,
|
||||
user_id: int,
|
||||
data: dict[str, Any],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> NotificationChannel | None:
|
||||
session.execute(
|
||||
update(NotificationChannel)
|
||||
@@ -127,7 +127,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
self,
|
||||
channel_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
result = session.execute(
|
||||
delete(NotificationChannel)
|
||||
@@ -143,7 +143,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
def record_delivery(
|
||||
self,
|
||||
channel_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
update(NotificationChannel)
|
||||
@@ -162,7 +162,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
channel_id: int,
|
||||
error: str,
|
||||
counts: bool,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
"""Keep a failed delivery's error; one that `counts` brings the channel closer to off."""
|
||||
values: dict[str, Any] = {
|
||||
@@ -183,7 +183,7 @@ class DBNotificationChannelsHandler(DBBaseHandler):
|
||||
def turn_off_if_failing(
|
||||
self,
|
||||
channel_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> bool:
|
||||
"""Turn the channel off once it failed too often in a row; True if this call did."""
|
||||
result = session.execute(
|
||||
|
||||
@@ -24,7 +24,7 @@ class DBNotificationsHandler(DBBaseHandler):
|
||||
def add_notifications(
|
||||
self,
|
||||
notifications: Sequence[Notification],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Notification]:
|
||||
"""Store notifications and trim their users' inboxes; returns the rows kept."""
|
||||
session.add_all(notifications)
|
||||
@@ -61,7 +61,7 @@ class DBNotificationsHandler(DBBaseHandler):
|
||||
def get_notifications(
|
||||
self,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Notification]:
|
||||
return session.scalars(
|
||||
select(Notification)
|
||||
@@ -75,7 +75,7 @@ class DBNotificationsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
ids: list[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
"""Mark the user's unread notifications read, all of them when `ids` is None."""
|
||||
stmt = update(Notification).where(
|
||||
@@ -95,7 +95,7 @@ class DBNotificationsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
ids: list[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Delete the user's notifications, all of them when `ids` is None."""
|
||||
stmt = delete(Notification).where(Notification.user_id == user_id)
|
||||
|
||||
@@ -34,7 +34,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def get_default_group(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> PermissionGroup | None:
|
||||
return session.scalar(
|
||||
select(PermissionGroup).filter_by(is_default=True).limit(1)
|
||||
@@ -44,7 +44,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
def get_group_grants(
|
||||
self,
|
||||
group_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[PermissionGroupGrant]:
|
||||
return session.scalars(
|
||||
select(PermissionGroupGrant).filter_by(group_id=group_id)
|
||||
@@ -54,7 +54,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
def get_user_overrides(
|
||||
self,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[UserPermissionOverride]:
|
||||
return session.scalars(
|
||||
select(UserPermissionOverride).filter_by(user_id=user_id)
|
||||
@@ -66,7 +66,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
entity: PermEntity,
|
||||
user_id: int | None,
|
||||
group_id: int | None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> set[int]:
|
||||
"""Ids of `entity` hidden from the given user OR their group.
|
||||
|
||||
@@ -93,7 +93,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def get_groups(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[PermissionGroup]:
|
||||
return (
|
||||
session.scalars(select(PermissionGroup).order_by(PermissionGroup.name))
|
||||
@@ -105,7 +105,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
def get_group(
|
||||
self,
|
||||
group_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> PermissionGroup | None:
|
||||
return session.get(PermissionGroup, group_id)
|
||||
|
||||
@@ -113,7 +113,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
def get_group_by_name(
|
||||
self,
|
||||
name: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> PermissionGroup | None:
|
||||
return session.scalar(select(PermissionGroup).filter_by(name=name).limit(1))
|
||||
|
||||
@@ -125,7 +125,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
is_default: bool = False,
|
||||
color: str | None = None,
|
||||
grants: Iterable[GrantTuple] = (),
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> PermissionGroup:
|
||||
group = PermissionGroup(
|
||||
name=name,
|
||||
@@ -152,7 +152,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
is_default: bool | None = None,
|
||||
color: str | None = None,
|
||||
grants: Iterable[GrantTuple] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> PermissionGroup | None:
|
||||
group = session.get(PermissionGroup, group_id)
|
||||
if group is None:
|
||||
@@ -177,7 +177,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
def delete_group(
|
||||
self,
|
||||
group_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(delete(PermissionGroup).where(PermissionGroup.id == group_id))
|
||||
|
||||
@@ -208,7 +208,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
def get_group_member_ids(
|
||||
self,
|
||||
group_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
return list(
|
||||
session.scalars(
|
||||
@@ -223,7 +223,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
group_id: int | None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
update(User)
|
||||
@@ -237,7 +237,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
overrides: Iterable[OverrideTuple],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(UserPermissionOverride).where(
|
||||
@@ -263,7 +263,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
*,
|
||||
user_id: int | None = None,
|
||||
group_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[HiddenEntity]:
|
||||
query = select(HiddenEntity)
|
||||
if user_id is not None:
|
||||
@@ -280,7 +280,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
*,
|
||||
user_id: int | None = None,
|
||||
group_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
# Idempotent: a repeated hide is a no-op rather than a unique violation.
|
||||
existing = session.scalar(
|
||||
@@ -311,7 +311,7 @@ class DBPermissionsHandler(DBBaseHandler):
|
||||
*,
|
||||
user_id: int | None = None,
|
||||
group_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(HiddenEntity).where(
|
||||
|
||||
@@ -29,8 +29,8 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
def add_platform(
|
||||
self,
|
||||
platform: Platform,
|
||||
query: Select[tuple[Platform]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Platform]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Platform:
|
||||
platform = session.merge(platform)
|
||||
session.flush()
|
||||
@@ -42,7 +42,7 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Platform:
|
||||
session.execute(
|
||||
update(Platform)
|
||||
@@ -57,8 +57,8 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
def get_platform(
|
||||
self,
|
||||
id: int,
|
||||
query: Select[tuple[Platform]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Platform]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Platform | None:
|
||||
return session.scalar(query.filter_by(id=id).limit(1))
|
||||
|
||||
@@ -68,8 +68,8 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
self,
|
||||
updated_after: datetime | None = None,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
query: Select[tuple[Platform]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Platform]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Platform]:
|
||||
if updated_after:
|
||||
query = query.filter(Platform.updated_at > updated_after)
|
||||
@@ -85,7 +85,7 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
def get_platform_ids(
|
||||
self,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
"""Ids only, deliberately off `with_firmware`: its eager load fires anyway."""
|
||||
query = select(Platform).order_by(Platform.name.asc())
|
||||
@@ -100,8 +100,8 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
def get_platform_by_fs_slug(
|
||||
self,
|
||||
fs_slug: str,
|
||||
query: Select[tuple[Platform]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Platform]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Platform | None:
|
||||
platform = session.scalar(query.filter_by(fs_slug=fs_slug).limit(1))
|
||||
if platform:
|
||||
@@ -118,8 +118,8 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
def get_platform_by_slug(
|
||||
self,
|
||||
slug: str,
|
||||
query: Select[tuple[Platform]] = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: Select[tuple[Platform]] = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Platform | None:
|
||||
return session.scalar(query.filter_by(slug=slug).limit(1))
|
||||
|
||||
@@ -127,7 +127,7 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
def delete_platform(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
# Remove all roms from that platforms first
|
||||
session.execute(
|
||||
@@ -146,7 +146,7 @@ class DBPlatformsHandler(DBBaseHandler):
|
||||
def mark_missing_platforms(
|
||||
self,
|
||||
fs_platforms_to_keep: list[str],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Platform]:
|
||||
missing_platforms = (
|
||||
session.scalars(
|
||||
|
||||
@@ -15,7 +15,7 @@ class DBPlaySessionsHandler(DBBaseHandler):
|
||||
def add_sessions(
|
||||
self,
|
||||
play_sessions: list[PlaySession],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[PlaySession]:
|
||||
session.add_all(play_sessions)
|
||||
session.flush()
|
||||
@@ -27,7 +27,7 @@ class DBPlaySessionsHandler(DBBaseHandler):
|
||||
user_id: int,
|
||||
device_id: str | None,
|
||||
rom_start_pairs: list[tuple[int | None, datetime]],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> set[tuple[int | None, datetime]]:
|
||||
"""Return which (rom_id, start_time) pairs already exist for this user+device."""
|
||||
if not rom_start_pairs:
|
||||
@@ -75,7 +75,7 @@ class DBPlaySessionsHandler(DBBaseHandler):
|
||||
end_before: datetime | None = None,
|
||||
limit: int | None = 50,
|
||||
offset: int = 0,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[PlaySession]:
|
||||
stmt = select(PlaySession).filter_by(user_id=user_id)
|
||||
|
||||
@@ -99,7 +99,7 @@ class DBPlaySessionsHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
rom_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
result = session.scalar(
|
||||
select(func.sum(PlaySession.duration_ms)).where(
|
||||
@@ -114,7 +114,7 @@ class DBPlaySessionsHandler(DBBaseHandler):
|
||||
self,
|
||||
session_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> bool:
|
||||
result = session.execute(
|
||||
delete(PlaySession)
|
||||
|
||||
@@ -79,7 +79,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def get_feature_rows(
|
||||
self, session: Session = None # type: ignore
|
||||
self, session: Session = None # type: ignore[assignment]
|
||||
) -> list[RomFeatureRow]:
|
||||
"""Every ROM's facet values, for building the library-wide IDF.
|
||||
|
||||
@@ -112,7 +112,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def get_rom_igdb_ids(
|
||||
self, session: Session = None # type: ignore
|
||||
self, session: Session = None # type: ignore[assignment]
|
||||
) -> dict[int, int]:
|
||||
"""ROM id -> IGDB id, for resolving IGDB's related-game ids to owned copies."""
|
||||
stmt = select(RomFacets.rom_id, RomFacets.igdb_id).where(
|
||||
@@ -122,7 +122,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def get_rom_identity_ids(
|
||||
self, session: Session = None # type: ignore
|
||||
self, session: Session = None # type: ignore[assignment]
|
||||
) -> dict[int, frozenset[str]]:
|
||||
"""ROM id -> "provider:id" tokens from every provider that matched it.
|
||||
|
||||
@@ -146,7 +146,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def iter_igdb_related(
|
||||
self, session: Session = None # type: ignore
|
||||
self, session: Session = None # type: ignore[assignment]
|
||||
) -> Iterator[tuple[int, list[int]]]:
|
||||
"""Stream each ROM's IGDB related-game ids out of its metadata blob.
|
||||
|
||||
@@ -184,7 +184,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def get_collection_membership_sets(
|
||||
self, session: Session = None # type: ignore
|
||||
self, session: Session = None # type: ignore[assignment]
|
||||
) -> list[list[int]]:
|
||||
"""ROM ids grouped by user collection, for co-membership scoring."""
|
||||
stmt = select(CollectionRom.collection_id, CollectionRom.rom_id).order_by(
|
||||
@@ -194,7 +194,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def get_played_sets(
|
||||
self, session: Session = None # type: ignore
|
||||
self, session: Session = None # type: ignore[assignment]
|
||||
) -> list[list[int]]:
|
||||
"""ROM ids grouped by user, restricted to games they actually played.
|
||||
|
||||
@@ -232,7 +232,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_ids: Sequence[int],
|
||||
edges: Sequence[dict[str, Any]],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Swap in a batch of ROMs' edges.
|
||||
|
||||
@@ -256,7 +256,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
def get_stored_edges(
|
||||
self,
|
||||
rom_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict[int, list[tuple[float, int]]]:
|
||||
"""Each ROM's current neighbours, for a top-up to merge new ones into.
|
||||
|
||||
@@ -276,7 +276,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
return stored
|
||||
|
||||
@begin_session
|
||||
def count_similarity_edges(self, session: Session = None) -> int: # type: ignore
|
||||
def count_similarity_edges(self, session: Session = None) -> int: # type: ignore[assignment]
|
||||
return session.scalar(select(func.count()).select_from(RomSimilarity)) or 0
|
||||
|
||||
# --- Reads -------------------------------------------------------------------
|
||||
@@ -286,7 +286,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_id: int,
|
||||
limit: int = 20,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[SimilarRomEdge]:
|
||||
"""Top precomputed neighbours of one ROM, best first.
|
||||
|
||||
@@ -314,7 +314,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_ids: Sequence[int],
|
||||
limit_per_rom: int = 20,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[tuple[int, int, float, list[dict[str, Any]]]]:
|
||||
"""Edges fanning out from a set of seed ROMs, for the personalised feed.
|
||||
|
||||
@@ -352,7 +352,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
def get_user_affinity(
|
||||
self,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[UserAffinityRow]:
|
||||
"""Everything the user has done with each ROM, plus total playtime.
|
||||
|
||||
@@ -402,7 +402,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
def get_rom_names(
|
||||
self,
|
||||
rom_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict[int, str]:
|
||||
"""Display names only, for the "Because you played X" attribution."""
|
||||
if not rom_ids:
|
||||
@@ -419,7 +419,7 @@ class DBRecommendationsHandler(DBBaseHandler):
|
||||
self,
|
||||
limit: int,
|
||||
exclude_rom_ids: Sequence[int] = (),
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
"""Cold-start feed: the best-reviewed games in the library.
|
||||
|
||||
|
||||
@@ -714,8 +714,8 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def add_rom(
|
||||
self,
|
||||
rom: Rom,
|
||||
query: RomSelect = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: RomSelect = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Rom:
|
||||
rom = session.merge(rom)
|
||||
session.flush()
|
||||
@@ -728,8 +728,8 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
*,
|
||||
query: RomSelect = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: RomSelect = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Rom | None:
|
||||
return session.scalar(query.filter_by(id=id).limit(1))
|
||||
|
||||
@@ -738,7 +738,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomVisibility | None:
|
||||
"""The id and platform id a visibility check needs, nothing else."""
|
||||
row = session.execute(
|
||||
@@ -755,7 +755,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomVisibilityLabel | None:
|
||||
"""`get_rom_visibility` plus the name pair the file-delete logs need."""
|
||||
row = session.execute(
|
||||
@@ -774,7 +774,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomDeletionTarget | None:
|
||||
"""The columns the bulk-delete route reads off one rom, and no relations."""
|
||||
row = session.execute(
|
||||
@@ -812,8 +812,8 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
*,
|
||||
query: RomSelect = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: RomSelect = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Rom | None:
|
||||
"""Get a rom by ID with only the loads `SimpleRomSchema` needs."""
|
||||
return session.scalar(query.filter_by(id=id).limit(1))
|
||||
@@ -824,8 +824,8 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
ids: list[int],
|
||||
*,
|
||||
query: RomSelect = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: RomSelect = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Rom]:
|
||||
"""Get multiple ROMs by their IDs."""
|
||||
if not ids:
|
||||
@@ -838,8 +838,8 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
ids: Sequence[int],
|
||||
*,
|
||||
query: RomSelect = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: RomSelect = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Rom]:
|
||||
"""Get multiple ROMs by ID with only the loads `SimpleRomSchema` needs."""
|
||||
if not ids:
|
||||
@@ -1036,7 +1036,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
smart_collection: SmartCollection,
|
||||
rom_ids: Iterable[int],
|
||||
user_id: int | None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> set[int]:
|
||||
"""Which of `rom_ids` currently match the collection's criteria.
|
||||
|
||||
@@ -1419,7 +1419,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
include_notes: bool = True,
|
||||
hidden_platform_ids: abc.Collection[int] | None = None,
|
||||
hidden_rom_ids: abc.Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Select:
|
||||
from handler.scan_handler import MetadataSource
|
||||
|
||||
@@ -1833,7 +1833,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
order_dir: str = "asc",
|
||||
search_term: str | None = None,
|
||||
user_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[RomSelect, _GallerySortKey]:
|
||||
query = self._join_rom_user(select(Rom), user_id)
|
||||
order_dir = order_dir.lower()
|
||||
@@ -1894,7 +1894,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def get_roms_scalar(
|
||||
self,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
**kwargs,
|
||||
) -> Sequence[Rom]:
|
||||
query = self._scoped_roms_query(session=session, **kwargs)
|
||||
@@ -1904,7 +1904,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def get_rom_ids(
|
||||
self,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
**kwargs,
|
||||
) -> list[int]:
|
||||
"""Every matching rom id, in query order."""
|
||||
@@ -1919,7 +1919,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
rom_ids: Sequence[int],
|
||||
hidden_platform_ids: abc.Collection[int] | None,
|
||||
hidden_rom_ids: abc.Collection[int] | None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> set[int]:
|
||||
"""Of `rom_ids`, the subset hidden from the caller (own hide or platform)."""
|
||||
candidates = set(rom_ids)
|
||||
@@ -1942,7 +1942,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
*,
|
||||
cache_key: str | None = None,
|
||||
order_dir: str = "asc",
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[tuple[str, int]]:
|
||||
# Letter offsets only index a lexically ordered result. `Enum` subclasses
|
||||
# `String`, but the database orders native enums by declaration order.
|
||||
@@ -1997,7 +1997,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
query: RomSelect,
|
||||
*,
|
||||
cache_key: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
"""Return every matching rom id in query order.
|
||||
|
||||
@@ -2027,7 +2027,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
query: RomSelect,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Count matching roms without materialising their ids.
|
||||
|
||||
@@ -2047,7 +2047,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
query: RomSelect,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int | None:
|
||||
"""Pick one rom id at random, uniformly, from a filtered query.
|
||||
|
||||
@@ -2093,7 +2093,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
platform_id: int,
|
||||
fs_names: Iterable[str],
|
||||
with_files: bool = False,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict[str, Rom]:
|
||||
"""Retrieve a dictionary of roms keyed by their full path (fs_path/fs_name).
|
||||
|
||||
@@ -2135,7 +2135,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def get_roms_by_fs_names_no_ext(
|
||||
self,
|
||||
fs_names_no_ext: Iterable[str],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[Rom]:
|
||||
"""ROMs on any platform with one of these extensionless file names."""
|
||||
names = list(dict.fromkeys(fs_names_no_ext))
|
||||
@@ -2155,7 +2155,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Rom:
|
||||
if "name" in data and "name_sort_key" not in data:
|
||||
# Re-derive the key from the new name, but only when the stored key
|
||||
@@ -2203,7 +2203,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
id: int,
|
||||
folder: str,
|
||||
file_path: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
parts = compute_file_name_parts(folder)
|
||||
stored = session.scalars(select(Rom).filter_by(id=id)).one()
|
||||
@@ -2226,7 +2226,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def delete_rom(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(Rom)
|
||||
@@ -2238,7 +2238,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def get_missing_rom_ids(
|
||||
self,
|
||||
platform_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> set[int]:
|
||||
"""Return the ids of a platform's ROMs currently flagged missing."""
|
||||
return set(
|
||||
@@ -2257,7 +2257,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
platform_id: int,
|
||||
rom_ids: list[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
"""Bulk set missing_from_fs=False for a list of ROM IDs.
|
||||
|
||||
@@ -2288,7 +2288,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
platform_id: int,
|
||||
fs_roms_to_keep: list[str],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Rom]:
|
||||
"""Sync `missing_from_fs` for a platform against the keep-list.
|
||||
|
||||
@@ -2349,7 +2349,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomUser:
|
||||
rom_user = session.merge(RomUser(rom_id=rom_id, user_id=user_id))
|
||||
session.flush()
|
||||
@@ -2363,7 +2363,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomUser | None:
|
||||
return session.scalar(
|
||||
select(RomUser).filter_by(rom_id=rom_id, user_id=user_id).limit(1)
|
||||
@@ -2373,7 +2373,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def get_rom_user_by_id(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomUser | None:
|
||||
return session.scalar(select(RomUser).filter_by(id=id).limit(1))
|
||||
|
||||
@@ -2382,7 +2382,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomUser | None:
|
||||
session.execute(
|
||||
update(RomUser)
|
||||
@@ -2429,7 +2429,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def add_rom_file(
|
||||
self,
|
||||
rom_file: RomFile,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFile:
|
||||
merged = session.merge(rom_file)
|
||||
session.flush()
|
||||
@@ -2478,7 +2478,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_id: int,
|
||||
scanned_files: Sequence[RomFile],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SyncedRomFiles:
|
||||
"""Reconcile a ROM's file rows against a fresh scan, preserving row ids.
|
||||
|
||||
@@ -2569,7 +2569,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def get_rom_file_by_id(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFile | None:
|
||||
return session.scalar(
|
||||
select(RomFile)
|
||||
@@ -2588,7 +2588,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def get_rom_files_by_ids(
|
||||
self,
|
||||
ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[RomFile]:
|
||||
if not ids:
|
||||
return []
|
||||
@@ -2611,7 +2611,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
file_path: str,
|
||||
file_name: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFile | None:
|
||||
return session.scalar(
|
||||
select(RomFile)
|
||||
@@ -2625,7 +2625,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_id: int,
|
||||
category: RomFileCategory,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[RomFile]:
|
||||
"""Return the ROM's files for a single category, ordered by file_name."""
|
||||
return (
|
||||
@@ -2645,7 +2645,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def rom_files_for_rom_id(
|
||||
self,
|
||||
rom_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[RomFile]:
|
||||
"""Fetch a ROM's files on demand, with the `RomFile.rom` backref loaded."""
|
||||
return list(
|
||||
@@ -2666,7 +2666,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFile | None:
|
||||
session.execute(
|
||||
update(RomFile)
|
||||
@@ -2683,7 +2683,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
rom_file_id: int,
|
||||
rom_id: int,
|
||||
values: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> TrackMeta:
|
||||
existing = session.get(TrackMeta, rom_file_id)
|
||||
if existing:
|
||||
@@ -2701,7 +2701,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def delete_track_meta(
|
||||
self,
|
||||
rom_file_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(delete(TrackMeta).where(TrackMeta.rom_file_id == rom_file_id))
|
||||
|
||||
@@ -2713,7 +2713,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
rom_file_id: int,
|
||||
rom_id: int,
|
||||
values: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFileDocMeta:
|
||||
"""Create or update the provenance sidecar for a document file."""
|
||||
existing = session.get(RomFileDocMeta, rom_file_id)
|
||||
@@ -2735,7 +2735,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
self,
|
||||
rom_file_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFileUser | None:
|
||||
return session.scalar(
|
||||
select(RomFileUser)
|
||||
@@ -2749,7 +2749,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
rom_file_id: int,
|
||||
user_id: int,
|
||||
values: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFileUser:
|
||||
"""Create or update a user's reading progress for a document file."""
|
||||
select_state = (
|
||||
@@ -2871,7 +2871,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
is_favorite_user_id: int | None = None,
|
||||
only_favorites: bool = False,
|
||||
playlist_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[Sequence[Any], int]:
|
||||
if only_favorites and is_favorite_user_id is None:
|
||||
return [], 0
|
||||
@@ -2992,7 +2992,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
order_dir: str = "desc",
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[Sequence[Any], int]:
|
||||
facet_columns = {
|
||||
"artists": (TrackMeta.artist, "artist"),
|
||||
@@ -3059,7 +3059,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
*,
|
||||
hidden_platform_ids: abc.Collection[int] | None = None,
|
||||
hidden_rom_ids: abc.Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[int, float]:
|
||||
"""Total track count and total duration, for the jukebox home cards.
|
||||
|
||||
@@ -3103,7 +3103,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
order_dir: str = "desc",
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[Sequence[Any], int]:
|
||||
"""Distinct *game* genres over the tracked roms, with track counts.
|
||||
|
||||
@@ -3185,7 +3185,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
order_dir: str = "asc",
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[Sequence[Any], int]:
|
||||
"""Platforms that have soundtrack tracks, with per-platform counts."""
|
||||
where = self._music_where(
|
||||
@@ -3252,7 +3252,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
order_dir: str = "asc",
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> tuple[Sequence[Any], int]:
|
||||
"""Games that have soundtrack tracks -- the jukebox's album list."""
|
||||
where = self._music_where(
|
||||
@@ -3315,7 +3315,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def delete_rom_file(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(RomFile)
|
||||
@@ -3363,7 +3363,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
public_only: bool = False,
|
||||
search: str | None = "",
|
||||
tags: list[str] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[RomNote]:
|
||||
return session.scalars(
|
||||
self._rom_notes_query(
|
||||
@@ -3384,7 +3384,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
public_only: bool = False,
|
||||
search: str | None = "",
|
||||
tags: list[str] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
"""Ids only, so no `RomNote` is built and no eager rom or user join fires."""
|
||||
query = self._rom_notes_query(
|
||||
@@ -3406,7 +3406,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
content: str = "",
|
||||
is_public: bool = False,
|
||||
tags: list[str] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict:
|
||||
note = RomNote(
|
||||
rom_id=rom_id,
|
||||
@@ -3438,7 +3438,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
note_id: int,
|
||||
user_id: int,
|
||||
rom_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
**fields,
|
||||
) -> dict | None:
|
||||
note = session.scalar(
|
||||
@@ -3479,7 +3479,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
note_id: int,
|
||||
user_id: int,
|
||||
rom_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> bool:
|
||||
result = session.execute(
|
||||
delete(RomNote).where(
|
||||
@@ -3510,8 +3510,8 @@ class DBRomsHandler(DBBaseHandler):
|
||||
csdb_id: int | None = None,
|
||||
steam_id: int | None = None,
|
||||
*,
|
||||
query: RomSelect = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: RomSelect = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Rom | None:
|
||||
"""
|
||||
Get a ROM by any metadata ID.
|
||||
@@ -3554,8 +3554,8 @@ class DBRomsHandler(DBBaseHandler):
|
||||
sha1_hash: str | None = None,
|
||||
ra_hash: str | None = None,
|
||||
*,
|
||||
query: RomSelect = None, # type: ignore
|
||||
session: Session = None, # type: ignore
|
||||
query: RomSelect = None, # type: ignore[assignment]
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Rom | None:
|
||||
"""
|
||||
Get a ROM by calculated hash value.
|
||||
@@ -3592,7 +3592,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
md5_hash: str | None = None,
|
||||
sha1_hash: str | None = None,
|
||||
title_id: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Rom | None:
|
||||
"""Find a ROM marked missing on a platform that identifies the file.
|
||||
|
||||
@@ -3699,7 +3699,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
def refresh_identity_key_statistics(
|
||||
self,
|
||||
*,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
"""Resample `rom_identity_keys` so the sibling join keeps its indexed plan.
|
||||
|
||||
@@ -3727,7 +3727,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
query: RomSelect,
|
||||
*,
|
||||
cache_key: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFiltersDict:
|
||||
"""
|
||||
Returns the list of filters given the current subset of ROMs in the query
|
||||
@@ -3753,7 +3753,7 @@ class DBRomsHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def get_rom_filters(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> RomFiltersDict:
|
||||
"""
|
||||
Returns all filter values across all ROM metadata
|
||||
|
||||
@@ -17,7 +17,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
def add_save(
|
||||
self,
|
||||
save: Save,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Save:
|
||||
return session.merge(save)
|
||||
|
||||
@@ -26,7 +26,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Save | None:
|
||||
return session.scalar(select(Save).filter_by(user_id=user_id, id=id).limit(1))
|
||||
|
||||
@@ -37,7 +37,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
file_name: str,
|
||||
slot: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Save | None:
|
||||
query = select(Save).filter_by(
|
||||
rom_id=rom_id, user_id=user_id, file_name=file_name
|
||||
@@ -55,7 +55,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
file_path: str,
|
||||
file_name: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Save | None:
|
||||
return session.scalars(
|
||||
select(Save)
|
||||
@@ -72,7 +72,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
content_hash: str,
|
||||
slot: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Save | None:
|
||||
query = select(Save).filter_by(
|
||||
rom_id=rom_id, user_id=user_id, content_hash=content_hash
|
||||
@@ -138,7 +138,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
file_name_prefix: str | None = None,
|
||||
order_by: Literal["updated_at", "created_at"] | None = None,
|
||||
order_dir: Literal["asc", "desc"] = "desc",
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Save]:
|
||||
query = self._saves_query(
|
||||
user_id=user_id,
|
||||
@@ -163,7 +163,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
slot_not_null: bool = False,
|
||||
order_by: Literal["updated_at", "created_at"] | None = None,
|
||||
order_dir: Literal["asc", "desc"] = "desc",
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
"""Ids only, so no `Save` is built and no eager rom or user join fires."""
|
||||
query = self._saves_query(
|
||||
@@ -181,7 +181,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
def get_save_by_id(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Save | None:
|
||||
"""Fetch a save by id without scoping to an owner. Used for the
|
||||
visibility toggle and community downloads, where the caller may not own
|
||||
@@ -194,7 +194,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
public_only: bool = False,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Save]:
|
||||
"""Saves for a ROM visible to the requesting user: own (public +
|
||||
private) plus other users' public ones. Mirrors
|
||||
@@ -214,7 +214,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
rom_ids: Sequence[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict[int, Save]:
|
||||
"""The most recent save per ROM for a user, keyed by `rom_id`.
|
||||
|
||||
@@ -242,7 +242,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
id: int,
|
||||
data: dict,
|
||||
touch: bool = True,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Save:
|
||||
"""Write `data` onto a save.
|
||||
|
||||
@@ -267,7 +267,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
slot: str,
|
||||
keep: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[tuple[str, str, str]]:
|
||||
"""Delete every version of a slot past the ``keep`` newest.
|
||||
|
||||
@@ -296,7 +296,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
def delete_save(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(Save)
|
||||
@@ -310,7 +310,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
saves_to_keep: list[str],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Save]:
|
||||
missing_saves = session.scalars(
|
||||
select(Save).filter(
|
||||
@@ -342,7 +342,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
rom_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict:
|
||||
saves = session.scalars(
|
||||
select(Save)
|
||||
@@ -365,7 +365,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def count_saves_missing_content_hash(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Number of Save rows whose content_hash is NULL. Used at startup to
|
||||
decide whether the one-shot recompute task needs to be enqueued."""
|
||||
@@ -381,7 +381,7 @@ class DBSavesHandler(DBBaseHandler):
|
||||
self,
|
||||
after_id: int,
|
||||
limit: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Save]:
|
||||
"""Page Save rows by primary key. Returns up to ``limit`` rows with
|
||||
``id > after_id``, ordered by id. Used by the
|
||||
|
||||
@@ -48,7 +48,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
def add_screenshot(
|
||||
self,
|
||||
screenshot: Screenshot,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Screenshot:
|
||||
return session.merge(screenshot)
|
||||
|
||||
@@ -58,7 +58,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
*,
|
||||
user_id: int,
|
||||
rom_ids: Collection[int],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Screenshot]:
|
||||
return session.scalars(
|
||||
select(Screenshot).filter(
|
||||
@@ -74,7 +74,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
user_id: int,
|
||||
file_name: str,
|
||||
file_name_no_ext: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Screenshot | None:
|
||||
query = self.filter(
|
||||
select(Screenshot),
|
||||
@@ -93,7 +93,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
def get_screenshot_by_id(
|
||||
self,
|
||||
id,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Screenshot | None:
|
||||
return session.get(Screenshot, id)
|
||||
|
||||
@@ -102,7 +102,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
self,
|
||||
screenshot: Screenshot,
|
||||
ignoring: Save | State | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> bool:
|
||||
"""Whether a save or state other than `ignoring` shows the screenshot
|
||||
as its thumbnail."""
|
||||
@@ -133,7 +133,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
def get_name_variants(
|
||||
self,
|
||||
screenshot: Screenshot,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Screenshot]:
|
||||
"""Other screenshots in the same folder whose name differs only in case."""
|
||||
query = self.filter(
|
||||
@@ -151,7 +151,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
public_only: bool = False,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Screenshot]:
|
||||
"""Gallery (intentionally-uploaded) screenshots for a ROM, visible to
|
||||
the requesting user. Mirrors `db_rom_handler.get_rom_notes`: own
|
||||
@@ -177,7 +177,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Screenshot:
|
||||
session.execute(
|
||||
update(Screenshot)
|
||||
@@ -191,7 +191,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
def delete_screenshot(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(Screenshot)
|
||||
@@ -205,7 +205,7 @@ class DBScreenshotsHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
screenshots_to_keep: list[str],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[Screenshot]:
|
||||
query_fn = partial(
|
||||
self.filter,
|
||||
|
||||
@@ -16,7 +16,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
def add_state(
|
||||
self,
|
||||
state: State,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> State:
|
||||
return session.merge(state)
|
||||
|
||||
@@ -25,7 +25,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
self,
|
||||
user_id: int,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> State | None:
|
||||
return session.scalar(select(State).filter_by(user_id=user_id, id=id).limit(1))
|
||||
|
||||
@@ -35,7 +35,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
user_id: int,
|
||||
rom_id: int,
|
||||
file_name: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> State | None:
|
||||
return session.scalar(
|
||||
select(State)
|
||||
@@ -68,7 +68,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
user_id: int,
|
||||
rom_ids: Collection[int] | None = None,
|
||||
platform_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[State]:
|
||||
query = self._states_query(
|
||||
user_id=user_id, rom_ids=rom_ids, platform_id=platform_id
|
||||
@@ -81,7 +81,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
user_id: int,
|
||||
rom_ids: Collection[int] | None = None,
|
||||
platform_id: int | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> list[int]:
|
||||
"""Ids only, so no `State` is built and no eager rom or user join fires."""
|
||||
query = self._states_query(
|
||||
@@ -93,7 +93,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
def get_state_by_id(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> State | None:
|
||||
"""Fetch a state by id without scoping to an owner. Used for the
|
||||
visibility toggle and community downloads, where the caller may not own
|
||||
@@ -106,7 +106,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
public_only: bool = False,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[State]:
|
||||
"""States for a ROM visible to the requesting user: own (public +
|
||||
private) plus other users' public ones. Mirrors
|
||||
@@ -127,7 +127,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
id: int,
|
||||
data: dict,
|
||||
touch: bool = True,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> State:
|
||||
"""Write `data` onto a state.
|
||||
|
||||
@@ -149,7 +149,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
def delete_state(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
delete(State)
|
||||
@@ -163,7 +163,7 @@ class DBStatesHandler(DBBaseHandler):
|
||||
rom_id: int,
|
||||
user_id: int,
|
||||
states_to_keep: list[str],
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[State]:
|
||||
missing_states = session.scalars(
|
||||
select(State).filter(
|
||||
|
||||
@@ -40,7 +40,7 @@ class DBStatsHandler(DBBaseHandler):
|
||||
self,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
hidden_rom_ids: Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Get the number of platforms with any roms."""
|
||||
query = _exclude_hidden(
|
||||
@@ -55,7 +55,7 @@ class DBStatsHandler(DBBaseHandler):
|
||||
self,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
hidden_rom_ids: Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
query = _exclude_hidden(
|
||||
select(func.count()).select_from(Rom),
|
||||
@@ -67,21 +67,21 @@ class DBStatsHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def get_saves_count(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
return session.scalar(select(func.count()).select_from(Save)) or 0
|
||||
|
||||
@begin_session
|
||||
def get_states_count(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
return session.scalar(select(func.count()).select_from(State)) or 0
|
||||
|
||||
@begin_session
|
||||
def get_screenshots_count(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
return session.scalar(select(func.count()).select_from(Screenshot)) or 0
|
||||
|
||||
@@ -90,7 +90,7 @@ class DBStatsHandler(DBBaseHandler):
|
||||
self,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
hidden_rom_ids: Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Get the total filesize of all roms in the database, in bytes."""
|
||||
query = select(func.sum(RomFile.file_size_bytes)).select_from(RomFile)
|
||||
@@ -104,7 +104,7 @@ class DBStatsHandler(DBBaseHandler):
|
||||
def get_platform_filesize(
|
||||
self,
|
||||
platform_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Get the total filesize of all roms in the database, in bytes."""
|
||||
return (
|
||||
@@ -122,7 +122,7 @@ class DBStatsHandler(DBBaseHandler):
|
||||
self,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
hidden_rom_ids: Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict[int, list[MetadataCoverageItem]]:
|
||||
"""Get the count of ROMs matched per metadata source, grouped by platform.
|
||||
|
||||
@@ -160,7 +160,7 @@ class DBStatsHandler(DBBaseHandler):
|
||||
self,
|
||||
hidden_platform_ids: Collection[int] | None = None,
|
||||
hidden_rom_ids: Collection[int] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> dict[int, list[RegionBreakdownItem]]:
|
||||
"""Get the count of ROMs per region, grouped by platform.
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
self,
|
||||
device_id: str,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SyncSession:
|
||||
sync_session = SyncSession(
|
||||
device_id=device_id,
|
||||
@@ -38,7 +38,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
self,
|
||||
session_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SyncSession | None:
|
||||
return session.scalar(
|
||||
select(SyncSession).filter_by(id=session_id, user_id=user_id).limit(1)
|
||||
@@ -49,7 +49,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
self,
|
||||
device_id: str,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SyncSession | None:
|
||||
return session.scalar(
|
||||
select(SyncSession)
|
||||
@@ -72,7 +72,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
self,
|
||||
session_id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SyncSession:
|
||||
session.execute(
|
||||
update(SyncSession)
|
||||
@@ -90,7 +90,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
self,
|
||||
session_id: int,
|
||||
user_id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> None:
|
||||
session.execute(
|
||||
update(SyncSession)
|
||||
@@ -107,7 +107,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
session_id: int,
|
||||
operations_completed: int = 0,
|
||||
operations_failed: int = 0,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SyncSession | None:
|
||||
"""Complete a session that is still open, or that the cleanup expired.
|
||||
|
||||
@@ -162,7 +162,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
self,
|
||||
session_id: int,
|
||||
error_message: str | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> SyncSession:
|
||||
session.execute(
|
||||
update(SyncSession)
|
||||
@@ -183,7 +183,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
def fail_stale_sessions(
|
||||
self,
|
||||
older_than: datetime,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> int:
|
||||
"""Fail every session opened before ``older_than`` and never closed.
|
||||
|
||||
@@ -220,7 +220,7 @@ class DBSyncSessionsHandler(DBBaseHandler):
|
||||
device_id: str | None = None,
|
||||
status: SyncSessionStatus | None = None,
|
||||
limit: int = 50,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[SyncSession]:
|
||||
query = select(SyncSession).filter_by(user_id=user_id)
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class DBUsersHandler(DBBaseHandler):
|
||||
def add_user(
|
||||
self,
|
||||
user: User,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> User:
|
||||
return session.merge(user)
|
||||
|
||||
@@ -49,7 +49,7 @@ class DBUsersHandler(DBBaseHandler):
|
||||
def get_user_by_username(
|
||||
self,
|
||||
username: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> User | None:
|
||||
query = self.filter(select(User), usernames=[username])
|
||||
return session.scalar(query.limit(1))
|
||||
@@ -58,7 +58,7 @@ class DBUsersHandler(DBBaseHandler):
|
||||
def get_user_by_email(
|
||||
self,
|
||||
email: str,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> User | None:
|
||||
query = self.filter(select(User), emails=[email])
|
||||
return session.scalar(query.limit(1))
|
||||
@@ -67,7 +67,7 @@ class DBUsersHandler(DBBaseHandler):
|
||||
def get_user(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> User | None:
|
||||
return session.get(User, id)
|
||||
|
||||
@@ -76,7 +76,7 @@ class DBUsersHandler(DBBaseHandler):
|
||||
self,
|
||||
id: int,
|
||||
data: dict,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> User:
|
||||
session.execute(
|
||||
update(User)
|
||||
@@ -95,7 +95,7 @@ class DBUsersHandler(DBBaseHandler):
|
||||
roles: Sequence[Role] = (),
|
||||
has_ra_username: bool | None = None,
|
||||
only_fields: Sequence[QueryableAttribute] | None = None,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[User]:
|
||||
query = self.filter(
|
||||
select(User),
|
||||
@@ -114,7 +114,7 @@ class DBUsersHandler(DBBaseHandler):
|
||||
def delete_user(
|
||||
self,
|
||||
id: int,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
):
|
||||
return session.execute(
|
||||
delete(User)
|
||||
@@ -125,7 +125,7 @@ class DBUsersHandler(DBBaseHandler):
|
||||
@begin_session
|
||||
def get_admin_users(
|
||||
self,
|
||||
session: Session = None, # type: ignore
|
||||
session: Session = None, # type: ignore[assignment]
|
||||
) -> Sequence[User]:
|
||||
query = self.filter(select(User), roles=[Role.ADMIN])
|
||||
return session.scalars(query).all()
|
||||
|
||||
@@ -564,7 +564,7 @@ class GamelistHandler(MetadataHandler):
|
||||
# Populate ROM-specific paths using the actual rom object
|
||||
if gamelist_metadata:
|
||||
rom_specific_paths = populate_rom_specific_paths(gamelist_metadata, rom)
|
||||
gamelist_metadata.update(**rom_specific_paths) # type: ignore
|
||||
gamelist_metadata.update(**rom_specific_paths) # type: ignore[call-arg]
|
||||
matched_rom["gamelist_metadata"] = gamelist_metadata
|
||||
|
||||
return matched_rom
|
||||
|
||||
@@ -739,9 +739,7 @@ def extract_tags_from_ss_dump(dump: SSGameRom) -> list[str]:
|
||||
"""Tags of one dump, from the flags it raises."""
|
||||
# ScreenScraper sends these flags as "1", not 1.
|
||||
return [
|
||||
tag
|
||||
for key, tag in _SS_DUMP_FLAG_TAGS
|
||||
if str(dump.get(key, "")).strip() == "1" # type: ignore[literal-required]
|
||||
tag for key, tag in _SS_DUMP_FLAG_TAGS if str(dump.get(key, "")).strip() == "1"
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from collections.abc import Awaitable, Callable, Collection, Iterable, Sequence
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from functools import partial
|
||||
from typing import Literal, NamedTuple, cast
|
||||
from typing import Literal, NamedTuple
|
||||
|
||||
from handler.database import (
|
||||
db_rom_handler,
|
||||
@@ -88,7 +88,7 @@ def parse_retroarch_sync_path(path: str) -> RetroArchSyncPath | None:
|
||||
|
||||
if segments[0] not in ASSET_ROOTS:
|
||||
return None
|
||||
kind = cast(AssetKind, segments[0])
|
||||
kind = segments[0]
|
||||
|
||||
emulator = None
|
||||
if len(segments) == 3:
|
||||
|
||||
@@ -117,7 +117,7 @@ def read_tar_file(
|
||||
|
||||
# Find the largest file among regular files only
|
||||
largest_file = max(regular_files, key=lambda x: x.size)
|
||||
with f.extractfile(largest_file) as ef: # type: ignore
|
||||
with f.extractfile(largest_file) as ef: # type: ignore[union-attr]
|
||||
with ef:
|
||||
while chunk := ef.read(FILE_READ_CHUNK_SIZE):
|
||||
yield chunk
|
||||
|
||||
Reference in New Issue
Block a user