fix(login): 为首次登录保留最低恢复预算
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 直播账号运营后台
|
||||
|
||||
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.14)。
|
||||
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.15)。
|
||||
|
||||
## 能做什么
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "live-hub-py"
|
||||
version = "0.4.14"
|
||||
version = "0.4.15"
|
||||
description = "直播账号运营 Web 后台"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12,<3.13"
|
||||
|
||||
@@ -547,6 +547,47 @@ def test_protected_account_reserves_quota_against_ordinary_backlog(db):
|
||||
assert protected_decision.attempt.category == CATEGORY_RELOGIN_PROTECTED
|
||||
|
||||
|
||||
def test_high_priority_backlog_leaves_hourly_floor_for_onboarding(db):
|
||||
from web.backend.models import LoginQuotaSetting
|
||||
from web.backend.services.login_quota_service import reserve_login_attempt
|
||||
|
||||
onboarding = _account("onboarding-floor", ck_status="")
|
||||
onboarding.cookie = ""
|
||||
onboarding.cookie_updated_at = None
|
||||
onboarding.status = "imported"
|
||||
ordinary = [
|
||||
_account(f"ordinary-floor-{index}", ck_status="invalid") for index in range(20)
|
||||
]
|
||||
db.add_all([onboarding, *ordinary, _health_job()])
|
||||
db.add(
|
||||
LoginQuotaSetting(
|
||||
id=1,
|
||||
daily_attempt_limit=100,
|
||||
hourly_attempt_limit=10,
|
||||
per_account_daily_limit=2,
|
||||
onboarding_daily_limit=10,
|
||||
relogin_ordinary_daily_limit=20,
|
||||
manual_daily_limit=10,
|
||||
enabled=True,
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
decision = reserve_login_attempt(
|
||||
db,
|
||||
account=onboarding,
|
||||
mode="login",
|
||||
trigger_source="automation",
|
||||
batch_id="b-onboarding-floor",
|
||||
created_by=None,
|
||||
now=NOW,
|
||||
)
|
||||
|
||||
assert decision.allowed
|
||||
assert decision.attempt is not None
|
||||
assert decision.attempt.category == "onboarding"
|
||||
|
||||
|
||||
def test_cascading_priority_quota_reservation_p0_p1_p2_p3(db):
|
||||
"""配额紧张时严格按 P0(保护失效) > P1(快过期) > P2(高价值) > P3(普通) 预留名额。"""
|
||||
from web.backend.models import LoginQuotaSetting
|
||||
|
||||
@@ -381,7 +381,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "live-hub-py"
|
||||
version = "0.4.14"
|
||||
version = "0.4.15"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "alembic" },
|
||||
|
||||
@@ -509,6 +509,17 @@ def _tier_reserve_needed(
|
||||
return reserved, "履约保护与高价值账号"
|
||||
|
||||
reserved += min(p3_pending, _remaining_cat(CATEGORY_RELOGIN_ORDINARY))
|
||||
daily_limit = int(setting.daily_attempt_limit)
|
||||
hourly_limit = int(setting.hourly_attempt_limit)
|
||||
daily_used = _daily_total(db, quota_day)
|
||||
hourly_used = _hourly_total(db, quota_day, _bucket(now)[1])
|
||||
daily_floor = max(1, daily_limit // 10) if daily_limit >= 20 else 0
|
||||
hourly_floor = max(1, hourly_limit // 10) if hourly_limit >= 10 else 0
|
||||
reserved = min(
|
||||
reserved,
|
||||
max(0, daily_limit - daily_used - daily_floor),
|
||||
max(0, hourly_limit - hourly_used - hourly_floor),
|
||||
)
|
||||
return reserved, "高优先级重登账号"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user