fix: 仅对需要重生成的日期联网补拉
This commit is contained in:
@ -302,13 +302,16 @@ def main():
|
|||||||
_, natural_week_end = week_bounds(current_week)
|
_, natural_week_end = week_bounds(current_week)
|
||||||
day_start = max(daily_start, month_start, current_week)
|
day_start = max(daily_start, month_start, current_week)
|
||||||
day_end = min(month_end, natural_week_end)
|
day_end = min(month_end, natural_week_end)
|
||||||
if args.fetch_missing:
|
|
||||||
for offset in range((day_end - day_start).days + 1):
|
def has_messages_or_fetch(day: date) -> bool:
|
||||||
ensure_day_synced(day_start + timedelta(days=offset))
|
if args.fetch_missing:
|
||||||
|
ensure_day_synced(day)
|
||||||
|
return has_messages(day)
|
||||||
|
|
||||||
for day in missing_message_dates(
|
for day in missing_message_dates(
|
||||||
day_start,
|
day_start,
|
||||||
day_end,
|
day_end,
|
||||||
has_messages,
|
has_messages_or_fetch,
|
||||||
output_for_day,
|
output_for_day,
|
||||||
args.overwrite,
|
args.overwrite,
|
||||||
refresh_tagged_from,
|
refresh_tagged_from,
|
||||||
|
|||||||
@ -76,3 +76,24 @@ def test_backfill_force_refreshes_all_daily_notes_from_requested_date(tmp_path):
|
|||||||
))
|
))
|
||||||
|
|
||||||
assert days == [date(2026, 10, 8), date(2026, 10, 9)]
|
assert days == [date(2026, 10, 8), date(2026, 10, 9)]
|
||||||
|
|
||||||
|
|
||||||
|
def test_backfill_does_not_probe_days_that_do_not_need_regeneration(tmp_path):
|
||||||
|
probes = []
|
||||||
|
|
||||||
|
def has_messages(day):
|
||||||
|
probes.append(day)
|
||||||
|
return True
|
||||||
|
|
||||||
|
for day in (date(2026, 2, 17), date(2026, 2, 18)):
|
||||||
|
(tmp_path / f"{day.isoformat()}.md").write_text("已有日报", encoding="utf-8")
|
||||||
|
|
||||||
|
days = list(missing_message_dates(
|
||||||
|
date(2026, 2, 17),
|
||||||
|
date(2026, 2, 18),
|
||||||
|
has_messages,
|
||||||
|
lambda day: tmp_path / f"{day.isoformat()}.md",
|
||||||
|
))
|
||||||
|
|
||||||
|
assert days == []
|
||||||
|
assert probes == [] # 已存在且无需重生成的日子不应触发拉取判断
|
||||||
|
|||||||
Reference in New Issue
Block a user