fix: 防止浏览时无限循环重复处理已处理文章
- 添加 processed_hrefs 集合跟踪已处理的文章 href - 处理文章前检查是否已处理过,避免重复处理 - 添加 new_articles_in_page 计数器,当前页无新文章时退出循环 - 解决 mark_read 未立即生效导致的无限循环问题 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -475,6 +475,7 @@ class APIBrowser:
|
|||||||
# 这样可以避免分页错位问题(标记已读后文章从列表消失导致后续页面上移)
|
# 这样可以避免分页错位问题(标记已读后文章从列表消失导致后续页面上移)
|
||||||
max_iterations = total_records + 10 # 防止无限循环
|
max_iterations = total_records + 10 # 防止无限循环
|
||||||
iteration = 0
|
iteration = 0
|
||||||
|
processed_hrefs = set() # 跟踪已处理的文章,防止重复处理
|
||||||
|
|
||||||
while articles and iteration < max_iterations:
|
while articles and iteration < max_iterations:
|
||||||
iteration += 1
|
iteration += 1
|
||||||
@@ -483,14 +484,24 @@ class APIBrowser:
|
|||||||
self.log("[API] 收到停止信号")
|
self.log("[API] 收到停止信号")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
new_articles_in_page = 0 # 本次迭代中新处理的文章数
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
if should_stop_callback and should_stop_callback():
|
if should_stop_callback and should_stop_callback():
|
||||||
break
|
break
|
||||||
|
|
||||||
|
article_href = article['href']
|
||||||
|
# 跳过已处理的文章
|
||||||
|
if article_href in processed_hrefs:
|
||||||
|
continue
|
||||||
|
|
||||||
|
processed_hrefs.add(article_href)
|
||||||
|
new_articles_in_page += 1
|
||||||
title = article['title'][:30]
|
title = article['title'][:30]
|
||||||
|
|
||||||
# 获取附件(文章详情页)
|
# 获取附件(文章详情页)
|
||||||
try:
|
try:
|
||||||
attachments = self.get_article_attachments(article['href'])
|
attachments = self.get_article_attachments(article_href)
|
||||||
consecutive_failures = 0
|
consecutive_failures = 0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
skipped_items += 1
|
skipped_items += 1
|
||||||
@@ -514,6 +525,11 @@ class APIBrowser:
|
|||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# 如果当前页没有新文章被处理,说明所有文章都已处理过,退出循环
|
||||||
|
if new_articles_in_page == 0:
|
||||||
|
self.log(f"[API] 当前页所有文章均已处理,结束循环")
|
||||||
|
break
|
||||||
|
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
# 重新获取第1页,检查是否还有未处理的内容
|
# 重新获取第1页,检查是否还有未处理的内容
|
||||||
|
|||||||
Reference in New Issue
Block a user