perf(douyu): 限制任务并发并释放长事务连接
This commit is contained in:
@@ -483,13 +483,21 @@ def lookup_account(
|
||||
"message": "账号不存在,请先到「账号管理」导入并登录",
|
||||
"account_username": _text(username, max_length=128),
|
||||
}
|
||||
manual_id = str(config.manual_id or "")
|
||||
rid = str(config.rid or "")
|
||||
act_alias = str(config.bind_act_alias or "")
|
||||
confirm_act_alias = str(config.confirm_act_alias or "")
|
||||
legacy_act_alias = str(config.legacy_act_alias or "")
|
||||
# 脱离 ORM 后提交,网络期间不持有连接,也不会因 commit 过期而重新查库。
|
||||
db.expunge(account)
|
||||
db.commit()
|
||||
probe = _probe_with_client(
|
||||
account,
|
||||
manual_id=str(config.manual_id or ""),
|
||||
rid=str(config.rid or ""),
|
||||
act_alias=str(config.bind_act_alias or ""),
|
||||
confirm_act_alias=str(config.confirm_act_alias or ""),
|
||||
legacy_act_alias=str(config.legacy_act_alias or ""),
|
||||
manual_id=manual_id,
|
||||
rid=rid,
|
||||
act_alias=act_alias,
|
||||
confirm_act_alias=confirm_act_alias,
|
||||
legacy_act_alias=legacy_act_alias,
|
||||
client=client,
|
||||
with_goods=with_goods,
|
||||
)
|
||||
@@ -1540,6 +1548,15 @@ def create_order(
|
||||
if exists is not None:
|
||||
raise CollabError("订单号已存在", status_code=409, code="order_no_exists")
|
||||
|
||||
owner_user_id = int(owner_id) if owner_id is not None else int(current.id)
|
||||
owner = db.get(User, owner_user_id)
|
||||
if owner is None or not owner.is_active:
|
||||
raise CollabError(
|
||||
"负责人不存在或已停用",
|
||||
status_code=400,
|
||||
code="owner_invalid",
|
||||
)
|
||||
|
||||
images = normalize_images(home_images)
|
||||
explicit_points = _to_int(required_points)
|
||||
name, cid, points = _resolve_gift(
|
||||
@@ -1551,7 +1568,7 @@ def create_order(
|
||||
order = DouyuExternalOrder(
|
||||
order_no=order_text,
|
||||
shop=_text(shop, max_length=64),
|
||||
owner_id=int(owner_id) if owner_id is not None else int(current.id),
|
||||
owner_id=owner_user_id,
|
||||
account_username=_text(account_username, max_length=128),
|
||||
gift_name=name,
|
||||
commodity_id=cid,
|
||||
@@ -1576,13 +1593,22 @@ def create_order(
|
||||
)
|
||||
if account is not None and not draft:
|
||||
config = resolve_config(db)
|
||||
manual_id = str(config.manual_id or "")
|
||||
rid = str(config.rid or "")
|
||||
act_alias = str(config.bind_act_alias or "")
|
||||
confirm_act_alias = str(config.confirm_act_alias or "")
|
||||
legacy_act_alias = str(config.legacy_act_alias or "")
|
||||
# order 还没有加入 Session。账号脱离 ORM 后提交,探针期间不占连接。
|
||||
db.expunge(account)
|
||||
db.commit()
|
||||
db.add(account)
|
||||
probe = _probe_with_client(
|
||||
account,
|
||||
manual_id=str(config.manual_id or ""),
|
||||
rid=str(config.rid or ""),
|
||||
act_alias=str(config.bind_act_alias or ""),
|
||||
confirm_act_alias=str(config.confirm_act_alias or ""),
|
||||
legacy_act_alias=str(config.legacy_act_alias or ""),
|
||||
manual_id=manual_id,
|
||||
rid=rid,
|
||||
act_alias=act_alias,
|
||||
confirm_act_alias=confirm_act_alias,
|
||||
legacy_act_alias=legacy_act_alias,
|
||||
client=client,
|
||||
with_goods=True,
|
||||
)
|
||||
@@ -3150,10 +3176,14 @@ def refresh_activity_goods(
|
||||
if account is None:
|
||||
raise CollabError("没有带 CK 的斗鱼账号,无法刷新活动商品", code="no_account")
|
||||
active_client = client or _client_for_account(account)
|
||||
config_info = config_mapping(config)
|
||||
db.expunge(account)
|
||||
db.commit()
|
||||
db.add(account)
|
||||
try:
|
||||
probe = probe_account(
|
||||
account,
|
||||
config,
|
||||
config_info,
|
||||
client=active_client,
|
||||
session_checker=None,
|
||||
with_elite=False,
|
||||
|
||||
Reference in New Issue
Block a user