fix(douyu): 拆分账号资格活动窗口与库存语义
This commit is contained in:
@@ -19,9 +19,7 @@ from ...models import (
|
||||
AccountEvent,
|
||||
AccountLease,
|
||||
)
|
||||
from ..account_capability_service import (
|
||||
AVAILABILITY_AVAILABLE,
|
||||
)
|
||||
from ..account_capability_service import OFFER_STATE_ACTIVE
|
||||
from ..account_events_service import (
|
||||
CATEGORY_OPS,
|
||||
EVENT_LEASE_ACQUIRED,
|
||||
@@ -34,7 +32,7 @@ from ..account_query_filters import (
|
||||
assigned_to_pool_filter,
|
||||
automatable_account_filter,
|
||||
cookie_present_filter,
|
||||
fresh_available_state_filter,
|
||||
fresh_eligible_state_filter,
|
||||
role_change_ready_filter,
|
||||
valid_ck_filter,
|
||||
)
|
||||
@@ -238,16 +236,16 @@ def _capability_candidate_query(
|
||||
scope: str = "elite",
|
||||
limit: int = 20,
|
||||
now: datetime | None = None,
|
||||
allow_not_open: bool = False,
|
||||
allow_before_open: bool = False,
|
||||
):
|
||||
commodity = commodity_id.strip()
|
||||
if not commodity:
|
||||
return None
|
||||
moment = _now(now)
|
||||
since = moment - timedelta(days=EXCHANGE_COOLDOWN_DAYS)
|
||||
availability_filter = fresh_available_state_filter(
|
||||
eligibility_filter = fresh_eligible_state_filter(
|
||||
moment,
|
||||
allow_not_open=allow_not_open,
|
||||
allow_before_open=allow_before_open,
|
||||
)
|
||||
return (
|
||||
db.query(Account, AccountCommodityState)
|
||||
@@ -259,7 +257,7 @@ def _capability_candidate_query(
|
||||
AccountCommodityState.platform == "douyu",
|
||||
AccountCommodityState.scope == scope,
|
||||
AccountCommodityState.commodity_id == commodity,
|
||||
availability_filter,
|
||||
eligibility_filter,
|
||||
or_(
|
||||
AccountCommodityState.last_exchange_at.is_(None),
|
||||
AccountCommodityState.last_exchange_at < since,
|
||||
@@ -274,7 +272,7 @@ def _capability_candidate_query(
|
||||
)
|
||||
.order_by(
|
||||
case(
|
||||
(AccountCommodityState.availability == AVAILABILITY_AVAILABLE, 0),
|
||||
(AccountCommodityState.offer_state == OFFER_STATE_ACTIVE, 0),
|
||||
else_=1,
|
||||
),
|
||||
case((Account.ck_check_status == "valid", 0), else_=1),
|
||||
@@ -300,7 +298,7 @@ def capability_candidate_rows(
|
||||
scope: str = "elite",
|
||||
limit: int = 20,
|
||||
now: datetime | None = None,
|
||||
allow_not_open: bool = False,
|
||||
allow_before_open: bool = False,
|
||||
) -> list[CapabilityCandidate]:
|
||||
"""读取账号与能力快照;只访问本地数据库,不触发官网请求。"""
|
||||
query = _capability_candidate_query(
|
||||
@@ -310,7 +308,7 @@ def capability_candidate_rows(
|
||||
scope=scope,
|
||||
limit=limit,
|
||||
now=now,
|
||||
allow_not_open=allow_not_open,
|
||||
allow_before_open=allow_before_open,
|
||||
)
|
||||
if query is None:
|
||||
return []
|
||||
@@ -328,7 +326,7 @@ def capability_candidate_accounts(
|
||||
scope: str = "elite",
|
||||
limit: int = 20,
|
||||
now: datetime | None = None,
|
||||
allow_not_open: bool = False,
|
||||
allow_before_open: bool = False,
|
||||
) -> list[Account]:
|
||||
"""从新鲜的商品能力索引读取候选账号,不产生外部请求。"""
|
||||
return [
|
||||
@@ -340,7 +338,7 @@ def capability_candidate_accounts(
|
||||
scope=scope,
|
||||
limit=limit,
|
||||
now=now,
|
||||
allow_not_open=allow_not_open,
|
||||
allow_before_open=allow_before_open,
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user