Skip to content

Commit 9ef5b59

Browse files
committed
fix: 宽限期从查询时间(checked_at)算起而非 API 数据日期
API 数据日期可能本身就在几天前(如周末不更新),导致宽限期 误判为过期。新增 checked_at 字段记录查询时间,宽限期从 该时间算起,确保检查更新的结果在关闭重开后仍有效。
1 parent 73dae10 commit 9ef5b59

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

quantclass_sync_internal/data_query.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ def get_products_overview(
9797
ref_date = api_date
9898
else:
9999
# 用缓存的 API 日期作为参考,避免周末/假日误报落后;
100-
# 缓存超过宽限期或无缓存时降级回 today,提示可能有新数据
100+
# 缓存超过宽限期或无缓存时降级回 today,提示可能有新数据。
101+
# 宽限期从"上次查询/同步时间"算起(checked_at 优先,降级到 date_time)
101102
cached_api_date = _parse_date(last.get("date_time", ""))
103+
freshness_anchor = _parse_date(last.get("checked_at", "")) or cached_api_date
102104
cache_fresh = (
103105
cached_api_date is not None
106+
and freshness_anchor is not None
104107
and today is not None
105-
and (today - cached_api_date).days <= _STALE_GRACE_DAYS
108+
and (today - freshness_anchor).days <= _STALE_GRACE_DAYS
106109
)
107110
ref_date = cached_api_date if cache_fresh else today
108111

quantclass_sync_internal/status_store.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,12 @@ def update_api_latest_dates(log_dir: Path, api_latest_dates: Dict[str, str]) ->
498498
existing = _scan_reports_for_backfill(log_dir)
499499
else:
500500
existing = _scan_reports_for_backfill(log_dir)
501+
checked_at = datetime.now().strftime("%Y-%m-%d")
501502
for product, date_str in api_latest_dates.items():
502503
if product in existing:
503504
existing[product]["date_time"] = date_str
505+
existing[product]["checked_at"] = checked_at
504506
else:
505-
existing[product] = {"status": "", "reason_code": "", "error": "", "date_time": date_str}
507+
existing[product] = {"status": "", "reason_code": "", "error": "", "date_time": date_str, "checked_at": checked_at}
506508
with atomic_temp_path(status_path, tag="last_status") as tmp:
507509
tmp.write_text(json.dumps(existing, ensure_ascii=False, indent=2), encoding="utf-8")

0 commit comments

Comments
 (0)