perf(fulfillment): 优化能力刷新候选查询并新增精英能力投影

This commit is contained in:
yml
2026-11-29 13:06:54 +08:00
parent 2ea105a924
commit be7146a9ef
12 changed files with 548 additions and 54 deletions
+77
View File
@@ -938,3 +938,80 @@ def test_valid_ck_older_than_24h_is_still_a_sync_candidate(db):
result = enqueue_supply_replenishment(db, now=NOW, max_per_target=10)
assert result.queued == 1
def test_elite_capability_projection_lifecycle_and_global_totals(db):
from web.backend.services.account_capability_service import (
invalidate_account_commodity_states,
mark_commodity_exchanged,
record_account_commodity_state,
sync_account_goods_states,
)
acc_sync = _account("proj-sync", points=400)
acc_limited = _account("proj-limited", points=0)
db.add_all([acc_sync, acc_limited])
db.commit()
sync_account_goods_states(
db,
acc_sync,
[
{"commodityId": "C1", "status": 0, "storeStatus": 1, "count": 5},
{"commodityId": "C2", "status": 1, "storeStatus": 1, "count": 5},
],
scope="elite",
observed_at=NOW,
)
record_account_commodity_state(
db,
acc_limited,
commodity_id="C1",
availability="available",
observed_at=NOW,
scope="elite",
)
db.commit()
db.refresh(acc_sync)
db.refresh(acc_limited)
assert acc_sync.elite_covered is True
assert acc_sync.elite_eligible_until is not None
assert acc_sync.elite_eligible_until > NOW
assert acc_limited.elite_covered is True
assert acc_limited.elite_eligible_until is not None
# 兑换唯一可兑换商品后,acc_limited 变为 covered 但不再 eligible
mark_commodity_exchanged(
db,
account_id=acc_limited.id,
commodity_id="C1",
occurred_at=NOW,
scope="elite",
)
db.commit()
db.refresh(acc_limited)
assert acc_limited.elite_covered is True
assert acc_limited.elite_eligible_until is None
totals = _global_inventory_totals(db, platform="douyu", scope="elite", now=NOW)
assert totals == {
"high_value": (1, 1, 1),
"ordinary": (1, 0, 0),
}
# 作废能力后清除可兑换有效期,覆盖仍保留
invalidate_account_commodity_states(
db,
account_id=acc_sync.id,
reason="ck invalid",
observed_at=NOW,
)
db.commit()
db.refresh(acc_sync)
assert acc_sync.elite_covered is True
assert acc_sync.elite_eligible_until is None
assert _global_inventory_totals(db, platform="douyu", scope="elite", now=NOW) == {
"high_value": (1, 0, 0),
"ordinary": (1, 0, 0),
}