mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
feat(providers): provider 摘要列表排序增加启用状态优先
后端查询和前端展示均按 is_active 降序、priority 升序、created_at 升序排列, 确保已启用的 provider 始终排在前面。
This commit is contained in:
@@ -4,7 +4,7 @@ Provider 摘要与健康监控 API
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any
|
||||
from typing import Any, Protocol
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, Request
|
||||
from sqlalchemy import case, func
|
||||
@@ -43,10 +43,26 @@ from src.services.cache.model_cache import ModelCacheService
|
||||
from src.services.cache.provider_cache import ProviderCacheService
|
||||
from src.utils.cache_decorator import cache_result
|
||||
|
||||
|
||||
class _HasProviderSortFields(Protocol):
|
||||
is_active: Any
|
||||
provider_priority: Any
|
||||
created_at: Any
|
||||
|
||||
|
||||
router = APIRouter(tags=["Provider Summary"])
|
||||
pipeline = get_pipeline()
|
||||
|
||||
|
||||
def _provider_summary_ordering(provider_model: _HasProviderSortFields) -> tuple[Any, Any, Any]:
|
||||
"""Provider 摘要列表排序:启用在前,其次按优先级与创建时间。"""
|
||||
return (
|
||||
case((provider_model.is_active == True, 0), else_=1).asc(),
|
||||
provider_model.provider_priority.asc(),
|
||||
provider_model.created_at.asc(),
|
||||
)
|
||||
|
||||
|
||||
@router.get("/summary", response_model=ProviderSummaryPageResponse)
|
||||
async def get_providers_summary(
|
||||
request: Request,
|
||||
@@ -821,7 +837,7 @@ class AdminProviderSummaryAdapter(AdminApiAdapter):
|
||||
total = query.count()
|
||||
|
||||
providers = (
|
||||
query.order_by(Provider.provider_priority.asc(), Provider.created_at.asc())
|
||||
query.order_by(*_provider_summary_ordering(Provider))
|
||||
.offset((self.page - 1) * self.page_size)
|
||||
.limit(self.page_size)
|
||||
.all()
|
||||
|
||||
Reference in New Issue
Block a user