From bcb5c4c2b7b4bb2296714b25df99990c1e115abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Wed, 14 Dec 2022 23:57:37 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Fix=20Cookies=20Cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/cookies/services.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/cookies/services.py b/core/cookies/services.py index ec09a18d..8d104041 100644 --- a/core/cookies/services.py +++ b/core/cookies/services.py @@ -42,18 +42,19 @@ class PublicCookiesService: user_list: List[int] = [] cookies_list = await self._repository.get_all_cookies(RegionEnum.HYPERION) # 从数据库获取2 for cookies in cookies_list: - if cookies.status and cookies.status == CookiesStatusEnum.STATUS_SUCCESS: - continue - user_list.append(cookies.user_id) - add, count = await self._cache.add_public_cookies(user_list, RegionEnum.HYPERION) - logger.info(f"国服公共Cookies池已经添加[{add}]个 当前成员数为[{count}]") + if cookies.status is None or cookies.status == CookiesStatusEnum.STATUS_SUCCESS: + user_list.append(cookies.user_id) + if len(user_list) > 0: + add, count = await self._cache.add_public_cookies(user_list, RegionEnum.HYPERION) + logger.info(f"国服公共Cookies池已经添加[{add}]个 当前成员数为[{count}]") user_list.clear() cookies_list = await self._repository.get_all_cookies(RegionEnum.HOYOLAB) for cookies in cookies_list: - if cookies.status and cookies.status == CookiesStatusEnum.STATUS_SUCCESS: + if cookies.status is None or cookies.status == CookiesStatusEnum.STATUS_SUCCESS: user_list.append(cookies.user_id) - add, count = await self._cache.add_public_cookies(user_list, RegionEnum.HOYOLAB) - logger.info(f"国际服公共Cookies池已经添加[{add}]个 当前成员数为[{count}]") + if len(user_list) > 0: + add, count = await self._cache.add_public_cookies(user_list, RegionEnum.HOYOLAB) + logger.info(f"国际服公共Cookies池已经添加[{add}]个 当前成员数为[{count}]") async def get_cookies(self, user_id: int, region: RegionEnum = RegionEnum.NULL): """获取公共Cookies