push the same limit/offset changes for maimai and ongeki

This commit is contained in:
2024-11-15 21:36:16 +07:00
parent 37d07e6035
commit 2f59d7b0d6
12 changed files with 952 additions and 540 deletions

View File

@ -1,13 +1,11 @@
from typing import Dict, List, Optional, Union
from typing import Dict, List, Optional
from sqlalchemy import Column, PrimaryKeyConstraint, Table, UniqueConstraint, and_
from sqlalchemy import Column, Table, UniqueConstraint
from sqlalchemy.dialects.mysql import insert
from sqlalchemy.engine import Row
from sqlalchemy.engine.base import Connection
from sqlalchemy.schema import ForeignKey
from sqlalchemy.sql import func, select
from sqlalchemy.sql.expression import exists
from sqlalchemy.types import JSON, TIMESTAMP, BigInteger, Boolean, Integer, String
from sqlalchemy.types import Boolean, Integer, String
from core.data.schema import BaseData, metadata
@ -232,11 +230,20 @@ class ChuniRomVersion():
return -1
class ChuniScoreData(BaseData):
async def get_courses(self, aime_id: int, limit: Optional[int] = None, offset: int = 0) -> Optional[List[Row]]:
async def get_courses(
self,
aime_id: int,
limit: Optional[int] = None,
offset: Optional[int] = None,
) -> Optional[List[Row]]:
sql = select(course).where(course.c.user == aime_id)
if limit is not None or offset is not None:
sql = sql.order_by(course.c.id)
if limit is not None:
sql = sql.order_by(course.c.id.asc()).limit(limit).offset(offset)
sql = sql.limit(limit)
if offset is not None:
sql = sql.offset(offset)
result = await self.execute(sql)
if result is None:
@ -260,14 +267,14 @@ class ChuniScoreData(BaseData):
aime_id: int,
levels: Optional[list[int]] = None,
limit: Optional[int] = None,
offset: int = 0,
offset: Optional[int] = None,
) -> Optional[List[Row]]:
condition = best_score.c.user == aime_id
if levels is not None:
condition &= best_score.c.level.in_(levels)
if limit is None:
if limit is None and offset is None:
sql = (
select(best_score)
.where(condition)
@ -278,16 +285,21 @@ class ChuniScoreData(BaseData):
select(best_score.c.musicId)
.distinct()
.where(condition)
.order_by(best_score.c.musicId.asc())
.limit(limit)
.offset(offset)
.subquery()
.order_by(best_score.c.musicId)
)
if limit is not None:
subq = subq.limit(limit)
if offset is not None:
subq = subq.offset(offset)
subq = subq.subquery()
sql = (
select(best_score)
.join(subq, best_score.c.musicId == subq.c.musicId)
.where(condition)
.order_by(best_score.c.musicId.asc(), best_score.c.level.asc())
.order_by(best_score.c.musicId, best_score.c.level)
)
result = await self.execute(sql)