From c86659428f092ea145c3d5710631ef90c686ff01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=AF=E5=A4=A7=E4=BE=A0?= Date: Fri, 13 Feb 2026 18:09:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(recommend):=20=E6=89=8B=E5=8A=A8=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=8E=A8=E8=8D=90=E7=BC=93=E5=AD=98=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=97=B6=E5=BC=BA=E5=88=B7=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/system.py | 10 ++++++++-- app/chain/recommend.py | 11 +++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/api/endpoints/system.py b/app/api/endpoints/system.py index 6673b0ae..6f8c7c81 100644 --- a/app/api/endpoints/system.py +++ b/app/api/endpoints/system.py @@ -615,7 +615,10 @@ def run_scheduler(jobid: str, """ if not jobid: return schemas.Response(success=False, message="命令不能为空!") - Scheduler().start(jobid) + if jobid in {"recommend_refresh", "cookiecloud"}: + Scheduler().start(jobid, manual=True) + else: + Scheduler().start(jobid) return schemas.Response(success=True) @@ -628,5 +631,8 @@ def run_scheduler2(jobid: str, if not jobid: return schemas.Response(success=False, message="命令不能为空!") - Scheduler().start(jobid) + if jobid in {"recommend_refresh", "cookiecloud"}: + Scheduler().start(jobid, manual=True) + else: + Scheduler().start(jobid) return schemas.Response(success=True) diff --git a/app/chain/recommend.py b/app/chain/recommend.py index 25bbdb0e..7747f3c8 100644 --- a/app/chain/recommend.py +++ b/app/chain/recommend.py @@ -6,7 +6,7 @@ from app.chain import ChainBase from app.chain.bangumi import BangumiChain from app.chain.douban import DoubanChain from app.chain.tmdb import TmdbChain -from app.core.cache import cached +from app.core.cache import cached, fresh from app.core.config import settings, global_vars from app.helper.image import ImageHelper from app.log import logger @@ -27,9 +27,11 @@ class RecommendChain(ChainBase, metaclass=Singleton): # 推荐缓存区域 recommend_cache_region = "recommend" - def refresh_recommend(self): + def refresh_recommend(self, manual: bool = False): """ 刷新推荐 + + :param manual: 手动触发 """ logger.debug("Starting to refresh Recommend data.") @@ -62,7 +64,9 @@ class RecommendChain(ChainBase, metaclass=Singleton): if method in methods_finished: continue logger.debug(f"Fetch {method.__name__} data for page {page}.") - data = method(page=page) + # 手动触发的刷新,总是需要获取最新数据 + with fresh(manual): + data = method(page=page) if not data: logger.debug("All recommendation methods have finished fetching data. Ending pagination early.") methods_finished.add(method) @@ -90,7 +94,6 @@ class RecommendChain(ChainBase, metaclass=Singleton): poster_path = data.get("poster_path") if poster_path: poster_url = poster_path.replace("original", "w500") - logger.debug(f"Caching poster image: {poster_url}") self.__fetch_and_save_image(poster_url) @staticmethod