From 43da92f6e66d3702d22fa1664e0c1b03743550bb Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 12:15:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20run=5Fonce=5Fbas?= =?UTF-8?q?ic=20=E4=B8=AD"=E5=8D=95=E9=97=B4=E6=A8=A1=E5=BC=8F=E6=B8=85?= =?UTF-8?q?=E7=90=86=E8=BF=87=E6=9C=9F=E9=A2=84=E7=BA=A6"=E5=9D=97?= =?UTF-8?q?=E5=88=B0=20cleanup=5Fexpired=5Freservations=5Fsingle=5Froom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将单间模式下"清理过期预约"逻辑(约 24 行)抽到 helper: - 写说明日志 - 调用 douyin_reservation_logic.cleanup_expired_reservations - 异常时记录错误日志 douyin_fudai.py: 1688 → 1670 行 (-18) fudai_detail_helpers.py: 2242 → 2273 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 26 +++------------- .../fudai_modules/fudai_detail_helpers.py | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index e891120..a8fb3e0 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -926,29 +926,11 @@ class fudai_analyse: # 抢占逻辑已删除,直接继续处理 else: # 单间模式:不需要回退,预约会在当前直播间自动识别和参与 - # 只需要清理过期的预约 - try: - self._log_kv( - "预约", - "[预约] 单间模式(needswitch=False):不执行预约回退,预约会在当前直播间自动识别和参与", - reservations_count=( - len(self.reservations) if self.reservations else 0 - ), - ) + from douyin.core.fudai_modules.fudai_detail_helpers import ( + cleanup_expired_reservations_single_room, + ) - # use module-level `douyin_reservation_logic` - douyin_reservation_logic.cleanup_expired_reservations( - self, self.reservations, _write_state - ) - except Exception as exc: - try: - self._log_kv( - "预约", - "[预约] 单间模式下清理过期预约时出错", - error=str(exc), - ) - except Exception: - pass + cleanup_expired_reservations_single_room(self, _write_state) except Exception: pass diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index b9b666c..17d13ab 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,37 @@ def log_screenshot_failed( pass +def cleanup_expired_reservations_single_room(analyser, write_state_callback) -> None: + """run_once_basic 单间模式(needswitch=False)下清理过期预约。 + + 单间模式不切换直播间,预约会在当前直播间自动识别和参与,因此只需要 + 调用 douyin_reservation_logic.cleanup_expired_reservations 清理过期项。 + """ + from douyin.reservation import reservation_logic as douyin_reservation_logic + + try: + analyser._log_kv( + "预约", + "[预约] 单间模式(needswitch=False):不执行预约回退,预约会在当前直播间自动识别和参与", + reservations_count=( + len(analyser.reservations) if analyser.reservations else 0 + ), + ) + + douyin_reservation_logic.cleanup_expired_reservations( + analyser, analyser.reservations, write_state_callback + ) + except Exception as exc: + try: + analyser._log_kv( + "预约", + "[预约] 单间模式下清理过期预约时出错", + error=str(exc), + ) + except Exception: + pass + + def reset_to_first_room_after_all_reservations_done( analyser, swipe_down_back_callback ) -> bool: