perf(douyu): 优化自动化中心运行总览加载
This commit is contained in:
@@ -28,6 +28,7 @@ from web.backend.schemas import DouyuSupplyTargetUpsert
|
||||
from web.backend.services.account_observability import (
|
||||
account_platform_status,
|
||||
account_platform_trends,
|
||||
account_supply_snapshot,
|
||||
)
|
||||
from web.backend.services.account_supply_service import (
|
||||
VALUE_HIGH,
|
||||
@@ -539,6 +540,70 @@ def test_account_platform_status_can_defer_trends(db):
|
||||
assert isinstance(trends["alerts"], list)
|
||||
|
||||
|
||||
def test_account_platform_status_compact_mode_defers_heavy_sections(db):
|
||||
account = _account("platform-compact", points=400)
|
||||
db.add(account)
|
||||
db.flush()
|
||||
db.add_all(
|
||||
[
|
||||
_state(account),
|
||||
AccountSupplyTarget(
|
||||
platform="douyu",
|
||||
scope="elite",
|
||||
commodity_id="C",
|
||||
value_class=VALUE_HIGH,
|
||||
target_covered=2,
|
||||
target_available=2,
|
||||
target_allocatable=1,
|
||||
),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
|
||||
status = account_platform_status(
|
||||
db,
|
||||
now=NOW,
|
||||
include_trends=False,
|
||||
include_supply=False,
|
||||
include_diagnostics=False,
|
||||
)
|
||||
|
||||
assert status["accounts"]["ck_valid"] == 1
|
||||
assert status["commodities"]["fresh_eligible"] == 1
|
||||
assert status["commodities"]["by_availability"] == {}
|
||||
assert status["sync_domains"] == {}
|
||||
assert status["supply_targets"] == []
|
||||
assert status["trends"] is None
|
||||
|
||||
|
||||
def test_account_supply_snapshot_loads_inventory_independently(db):
|
||||
account = _account("platform-supply-only", points=400)
|
||||
db.add(account)
|
||||
db.flush()
|
||||
db.add_all(
|
||||
[
|
||||
_state(account),
|
||||
AccountSupplyTarget(
|
||||
platform="douyu",
|
||||
scope="elite",
|
||||
commodity_id="C",
|
||||
value_class=VALUE_HIGH,
|
||||
target_covered=2,
|
||||
target_available=2,
|
||||
target_allocatable=1,
|
||||
),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
|
||||
snapshot = account_supply_snapshot(db, now=NOW)
|
||||
|
||||
assert snapshot["supply_targets"][0]["covered"] == 1
|
||||
assert snapshot["supply_targets"][0]["available"] == 1
|
||||
assert snapshot["supply_targets"][0]["target_available"] == 2
|
||||
assert {alert["code"] for alert in snapshot["alerts"]} == {"supply_shortage"}
|
||||
|
||||
|
||||
def test_account_platform_status_builds_seven_day_trends(db):
|
||||
account = _account("platform-trends", points=400)
|
||||
db.add(account)
|
||||
|
||||
@@ -42,7 +42,7 @@ TESTS_DIR = Path(__file__).resolve().parent
|
||||
PROJECT_ROOT = TESTS_DIR.parent
|
||||
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
|
||||
|
||||
HEAD_REVISION = "20261122_0117"
|
||||
HEAD_REVISION = "20261123_0118"
|
||||
|
||||
# 迁移新增、但不声明在模型里的复合查询索引。
|
||||
EXTRA_INDEXES = (
|
||||
|
||||
Reference in New Issue
Block a user