Spaces:
Running
Running
修复时间错乱
Browse files- db_utils.py +4 -3
- 云端_定时版本检测引擎.py +1 -2
db_utils.py
CHANGED
|
@@ -386,7 +386,7 @@ def record_view(data_file: str, item_id: str, user_account: str) -> Optional[Dic
|
|
| 386 |
- 使用 atomic_update 确保读-改-写在同一把锁内完成
|
| 387 |
- 高并发下不会丢失访问量
|
| 388 |
"""
|
| 389 |
-
from datetime import
|
| 390 |
|
| 391 |
# 用于在闭包中存储结果
|
| 392 |
result_container = [None]
|
|
@@ -418,8 +418,9 @@ def record_view(data_file: str, item_id: str, user_account: str) -> Optional[Dic
|
|
| 418 |
if "daily_views_date" not in target_item:
|
| 419 |
target_item["daily_views_date"] = ""
|
| 420 |
|
| 421 |
-
# 获取今天的日期字符串
|
| 422 |
-
|
|
|
|
| 423 |
|
| 424 |
# 检查是否需要重置日访问量
|
| 425 |
if target_item["daily_views_date"] != today_str:
|
|
|
|
| 386 |
- 使用 atomic_update 确保读-改-写在同一把锁内完成
|
| 387 |
- 高并发下不会丢失访问量
|
| 388 |
"""
|
| 389 |
+
from datetime import datetime, timedelta
|
| 390 |
|
| 391 |
# 用于在闭包中存储结果
|
| 392 |
result_container = [None]
|
|
|
|
| 418 |
if "daily_views_date" not in target_item:
|
| 419 |
target_item["daily_views_date"] = ""
|
| 420 |
|
| 421 |
+
# 获取今天的日期字符串(使用 UTC+8 时区)
|
| 422 |
+
now_utc8 = datetime.utcnow() + timedelta(hours=8)
|
| 423 |
+
today_str = now_utc8.date().isoformat() # "2026-04-02"
|
| 424 |
|
| 425 |
# 检查是否需要重置日访问量
|
| 426 |
if target_item["daily_views_date"] != today_str:
|
云端_定时版本检测引擎.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
# 云端_定时版本检测引擎.py
|
| 2 |
import asyncio
|
| 3 |
import datetime
|
| 4 |
-
from datetime import date
|
| 5 |
import httpx
|
| 6 |
import logging
|
| 7 |
import 数据库连接 as db
|
|
@@ -207,7 +206,7 @@ async def reset_daily_views_task():
|
|
| 207 |
|
| 208 |
while True:
|
| 209 |
now = datetime.datetime.utcnow() + datetime.timedelta(hours=8)
|
| 210 |
-
today =
|
| 211 |
|
| 212 |
# 计算距离今天 00:00 (UTC+8) 的秒数,如果过了就定在明天 00:00
|
| 213 |
next_run = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
|
|
| 1 |
# 云端_定时版本检测引擎.py
|
| 2 |
import asyncio
|
| 3 |
import datetime
|
|
|
|
| 4 |
import httpx
|
| 5 |
import logging
|
| 6 |
import 数据库连接 as db
|
|
|
|
| 206 |
|
| 207 |
while True:
|
| 208 |
now = datetime.datetime.utcnow() + datetime.timedelta(hours=8)
|
| 209 |
+
today = now.date().isoformat() # 使用 UTC+8 日期而非系统本地日期
|
| 210 |
|
| 211 |
# 计算距离今天 00:00 (UTC+8) 的秒数,如果过了就定在明天 00:00
|
| 212 |
next_run = now.replace(hour=0, minute=0, second=0, microsecond=0)
|