@@ -523,14 +523,27 @@ def update_api_latest_dates(log_dir: Path, api_latest_dates: Dict[str, object])
523523 continue
524524 latest_date = candidates [- 1 ]
525525 if product in existing :
526- existing [product ]["date_time" ] = latest_date
527526 existing [product ]["api_dates" ] = candidates
528- existing [product ]["checked_at" ] = checked_at
529- existing [product ]["source" ] = _SOURCE_API_CHECK
527+ existing [product ]["api_date_time" ] = latest_date
528+ existing [product ]["api_checked_at" ] = checked_at
529+ has_sync_payload = any (
530+ bool (existing [product ].get (field ))
531+ for field in ("status" , "reason_code" , "error" )
532+ )
533+ if has_sync_payload :
534+ existing [product ]["source" ] = _SOURCE_SYNC
535+ if not has_sync_payload and existing [product ].get ("source" ) != _SOURCE_SYNC :
536+ existing [product ]["date_time" ] = latest_date
537+ existing [product ]["checked_at" ] = checked_at
538+ existing [product ]["source" ] = _SOURCE_API_CHECK
530539 else :
531540 existing [product ] = {
532541 "status" : "" , "reason_code" : "" , "error" : "" ,
533- "date_time" : latest_date , "api_dates" : candidates , "checked_at" : checked_at ,
542+ "date_time" : latest_date ,
543+ "checked_at" : checked_at ,
544+ "api_date_time" : latest_date ,
545+ "api_checked_at" : checked_at ,
546+ "api_dates" : candidates ,
534547 "source" : _SOURCE_API_CHECK ,
535548 }
536549 with atomic_temp_path (status_path , tag = "last_status" ) as tmp :
@@ -557,11 +570,18 @@ def load_api_latest_dates(log_dir: Path) -> Dict[str, Tuple[List[str], str]]:
557570 for product , info in data .items ():
558571 if not isinstance (info , dict ):
559572 continue
560- # 只读取 check_updates 写入的记录,排除同步结果
573+ candidates = _normalize_api_date_candidates (
574+ info .get ("api_dates" , info .get ("api_date_time" , info .get ("date_time" )))
575+ )
576+ checked_at = info .get ("api_checked_at" ) or info .get ("checked_at" )
577+ # 新格式:只要显式存在 api_checked_at / api_date_time,即视为 API 检查缓存。
578+ if info .get ("api_checked_at" ) or info .get ("api_date_time" ):
579+ if candidates and isinstance (checked_at , str ):
580+ result [product ] = (candidates , checked_at )
581+ continue
582+ # 旧格式:只读取 source=="api_check" 的记录,排除同步结果。
561583 if info .get ("source" ) != _SOURCE_API_CHECK :
562584 continue
563- candidates = _normalize_api_date_candidates (info .get ("api_dates" , info .get ("date_time" )))
564- checked_at = info .get ("checked_at" )
565585 if candidates and isinstance (checked_at , str ):
566586 result [product ] = (candidates , checked_at )
567587 return result
0 commit comments