mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
✨ 适配 Trending (#539)
* ✨ 适配 v1 tetrio 的 Trending * 🗃️ 添加 compare_delta 配置项 * 🗃️ 添加 TETRIOLeagueUserMap 索引表 * ✨ 添加对比时间配置项 * ✨ 添加 compare_delta 解析函数 * ✨ 添加 Trending 类的 compare 方法 * 🗃️ 移除不正确的复合索引 * ✨ 定时任务拉取tl数据时同步更新索引 * ✨ 适配 trending * 🐛 修复 find_entry 在无 uid 时的索引返回逻辑 * 📝 修正 compare_delta 迁移父迁移注释 * 🗃️ 为非 PostgreSQL 回填迁移补充外键约束 * 🔒 迁移中使用参数绑定设置 PG 内存参数 * ✨ 修正 Trends 的 vs 为 adpm * 🐛 修正获取玩家 ID 的范围
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from asyncio import Lock
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from enum import Enum, auto
|
||||
from typing import TYPE_CHECKING, Literal, TypeVar, overload
|
||||
|
||||
@@ -11,6 +11,7 @@ from nonebot_plugin_orm import AsyncSession, get_session
|
||||
from nonebot_plugin_user import User
|
||||
from sqlalchemy import select
|
||||
|
||||
from ..utils.duration import DEFAULT_COMPARE_DELTA
|
||||
from ..utils.typedefs import AllCommandType, BaseCommandType, GameType, TETRIOCommandType
|
||||
from .models import Bind, TriggerHistoricalDataV2
|
||||
|
||||
@@ -18,8 +19,11 @@ UTC = timezone.utc
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..games.tetrio.api.models import TETRIOHistoricalData
|
||||
from ..games.tetrio.models import TETRIOUserConfig
|
||||
from ..games.top.api.models import TOPHistoricalData
|
||||
from ..games.top.models import TOPUserConfig
|
||||
from ..games.tos.api.models import TOSHistoricalData
|
||||
from ..games.tos.models import TOSUserConfig
|
||||
|
||||
|
||||
class BindStatus(Enum):
|
||||
@@ -84,12 +88,12 @@ async def remove_bind(
|
||||
return False
|
||||
|
||||
|
||||
T = TypeVar('T', 'TETRIOHistoricalData', 'TOPHistoricalData', 'TOSHistoricalData')
|
||||
T_HistoricalData = TypeVar('T_HistoricalData', 'TETRIOHistoricalData', 'TOPHistoricalData', 'TOSHistoricalData')
|
||||
|
||||
lock = Lock()
|
||||
|
||||
|
||||
async def anti_duplicate_add(model: T) -> None:
|
||||
async def anti_duplicate_add(model: T_HistoricalData) -> None:
|
||||
async with lock, get_session() as session:
|
||||
result = (
|
||||
await session.scalars(
|
||||
@@ -108,6 +112,19 @@ async def anti_duplicate_add(model: T) -> None:
|
||||
await session.commit()
|
||||
|
||||
|
||||
T_CONFIG = TypeVar('T_CONFIG', 'TETRIOUserConfig', 'TOPUserConfig', 'TOSUserConfig')
|
||||
|
||||
|
||||
async def resolve_compare_delta(
|
||||
config: type[T_CONFIG], session: AsyncSession, user_id: int, compare: timedelta | None
|
||||
) -> timedelta:
|
||||
return (
|
||||
compare
|
||||
or await session.scalar(select(config.compare_delta).where(config.id == user_id))
|
||||
or DEFAULT_COMPARE_DELTA
|
||||
)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@overload
|
||||
async def trigger(
|
||||
|
||||
Reference in New Issue
Block a user