refactor(fudai): 抽 run_once_basic 中"多间模式预约抢占"块到 process_reservation_multi_room_mode
将多间模式调用 process_reservation_attend_window 的逻辑(约 64 行)抽到 helper: - 写"开始调用"日志 - 调用 process_reservation_attend_window - 写返回结果日志 - 同步回写 focus_ref 和 after_action_ref 到 analyser - 抢占成功时设置 _current_attending_reservation_fudai=True douyin_fudai.py: 1648 → 1606 行 (-42) fudai_detail_helpers.py: 2328 → 2398 行 douyin_fudai.py 跌破 1700 行(4121 → 1606,本会话累计削减 2515 行 = -61%) 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
722b57a7b9
commit
5f713afc5c
2 files changed
+81
-53
No files matched your search
+11
-53
@@ -847,61 +847,19 @@ class fudai_analyse:
|
||||
|
||||
if needswitch_cfg:
|
||||
# 多间模式:需要回退到预约直播间
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] 多间模式:开始调用 process_reservation_attend_window",
|
||||
reservations_count=(
|
||||
len(self.reservations) if self.reservations else 0
|
||||
),
|
||||
room_pos=int(getattr(self, "room_pos", 0) or 0),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
preempted = (
|
||||
douyin_reservation_logic.process_reservation_attend_window(
|
||||
analyser=self,
|
||||
reservations=self.reservations,
|
||||
room_pos=int(getattr(self, "room_pos", 0) or 0),
|
||||
reservation_focus_until_ts_ref=focus_ref,
|
||||
reservation_after_action_pending_ref=after_action_ref,
|
||||
reservation_back_swipe_delay_s=float(
|
||||
self.reservation_back_swipe_delay or 0.6
|
||||
),
|
||||
swipe_down_back_callback=_swipe_down_once,
|
||||
seek_reservation_room_callback=_seek_reservation_room,
|
||||
sort_reservations_callback=_sort_reservations,
|
||||
write_state_callback=_write_state,
|
||||
)
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
process_reservation_multi_room_mode,
|
||||
)
|
||||
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window 返回结果",
|
||||
preempted=preempted,
|
||||
focus_until=(
|
||||
int(focus_ref[0])
|
||||
if focus_ref and focus_ref[0] > 0
|
||||
else 0
|
||||
),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 同步回写 ref 值
|
||||
if focus_ref:
|
||||
self.reservation_focus_until_ts = float(focus_ref[0] or 0.0)
|
||||
if after_action_ref:
|
||||
self.reservation_after_action_pending = bool(
|
||||
after_action_ref[0]
|
||||
)
|
||||
|
||||
# 如果抢占成功,设置当前参与的福袋类型为预约福袋
|
||||
if preempted:
|
||||
self._current_attending_reservation_fudai = True
|
||||
|
||||
# 抢占逻辑已删除,直接继续处理
|
||||
process_reservation_multi_room_mode(
|
||||
self,
|
||||
focus_ref,
|
||||
after_action_ref,
|
||||
_swipe_down_once,
|
||||
_seek_reservation_room,
|
||||
_sort_reservations,
|
||||
_write_state,
|
||||
)
|
||||
else:
|
||||
# 单间模式:不需要回退,预约会在当前直播间自动识别和参与
|
||||
from douyin.core.fudai_modules.fudai_detail_helpers import (
|
||||
|
||||
@@ -42,6 +42,76 @@ def log_screenshot_failed(
|
||||
pass
|
||||
|
||||
|
||||
def process_reservation_multi_room_mode(
|
||||
analyser,
|
||||
focus_ref,
|
||||
after_action_ref,
|
||||
swipe_down_back_callback,
|
||||
seek_reservation_room_callback,
|
||||
sort_reservations_callback,
|
||||
write_state_callback,
|
||||
) -> None:
|
||||
"""run_once_basic 多间模式:调用 process_reservation_attend_window 处理预约抢占。
|
||||
|
||||
流程:
|
||||
- 写"开始调用"日志
|
||||
- 调用 process_reservation_attend_window
|
||||
- 写返回结果日志
|
||||
- 同步回写 focus_ref 和 after_action_ref 到 analyser
|
||||
- 如果抢占成功,设置 _current_attending_reservation_fudai=True
|
||||
"""
|
||||
from douyin.reservation import reservation_logic as douyin_reservation_logic
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 多间模式:开始调用 process_reservation_attend_window",
|
||||
reservations_count=(
|
||||
len(analyser.reservations) if analyser.reservations else 0
|
||||
),
|
||||
room_pos=int(getattr(analyser, "room_pos", 0) or 0),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
preempted = douyin_reservation_logic.process_reservation_attend_window(
|
||||
analyser=analyser,
|
||||
reservations=analyser.reservations,
|
||||
room_pos=int(getattr(analyser, "room_pos", 0) or 0),
|
||||
reservation_focus_until_ts_ref=focus_ref,
|
||||
reservation_after_action_pending_ref=after_action_ref,
|
||||
reservation_back_swipe_delay_s=float(
|
||||
analyser.reservation_back_swipe_delay or 0.6
|
||||
),
|
||||
swipe_down_back_callback=swipe_down_back_callback,
|
||||
seek_reservation_room_callback=seek_reservation_room_callback,
|
||||
sort_reservations_callback=sort_reservations_callback,
|
||||
write_state_callback=write_state_callback,
|
||||
)
|
||||
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] process_reservation_attend_window 返回结果",
|
||||
preempted=preempted,
|
||||
focus_until=(
|
||||
int(focus_ref[0]) if focus_ref and focus_ref[0] > 0 else 0
|
||||
),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 同步回写 ref 值
|
||||
if focus_ref:
|
||||
analyser.reservation_focus_until_ts = float(focus_ref[0] or 0.0)
|
||||
if after_action_ref:
|
||||
analyser.reservation_after_action_pending = bool(after_action_ref[0])
|
||||
|
||||
# 如果抢占成功,设置当前参与的福袋类型为预约福袋
|
||||
if preempted:
|
||||
analyser._current_attending_reservation_fudai = True
|
||||
|
||||
|
||||
def try_handle_queue_full_wait(
|
||||
analyser,
|
||||
focus_ref,
|
||||
|
||||
Reference in new issue
Block a user