fix: 改进分页逻辑,确保遍历所有页面不漏掉内容
- 当前页有新文章时,重新获取第1页(已读文章消失后页面上移) - 当前页无新文章时,继续检查后续页面 - 遍历完所有页面后才结束循环 - 解决 mark_read 延迟导致后续页面内容被漏掉的问题 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -471,11 +471,11 @@ class APIBrowser:
|
|||||||
|
|
||||||
report_progress(force=True)
|
report_progress(force=True)
|
||||||
|
|
||||||
# 循环处理:每次获取第1页,直到没有内容
|
# 循环处理:遍历所有页面,跟踪已处理文章防止重复
|
||||||
# 这样可以避免分页错位问题(标记已读后文章从列表消失导致后续页面上移)
|
max_iterations = total_records + 20 # 防止无限循环
|
||||||
max_iterations = total_records + 10 # 防止无限循环
|
|
||||||
iteration = 0
|
iteration = 0
|
||||||
processed_hrefs = set() # 跟踪已处理的文章,防止重复处理
|
processed_hrefs = set() # 跟踪已处理的文章,防止重复处理
|
||||||
|
current_page = 1
|
||||||
|
|
||||||
while articles and iteration < max_iterations:
|
while articles and iteration < max_iterations:
|
||||||
iteration += 1
|
iteration += 1
|
||||||
@@ -525,18 +525,25 @@ 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页,检查是否还有未处理的内容
|
# 决定下一步获取哪一页
|
||||||
|
if new_articles_in_page > 0:
|
||||||
|
# 有新文章被处理,重新获取第1页(因为已读文章会从列表消失,页面会上移)
|
||||||
|
current_page = 1
|
||||||
|
else:
|
||||||
|
# 当前页没有新文章,尝试下一页
|
||||||
|
current_page += 1
|
||||||
|
if current_page > total_pages:
|
||||||
|
self.log(f"[API] 已遍历所有 {total_pages} 页,结束循环")
|
||||||
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
articles, _, _ = self.get_article_list_page(bz, 1)
|
articles, new_total_pages, _ = self.get_article_list_page(bz, current_page)
|
||||||
|
if new_total_pages > 0:
|
||||||
|
total_pages = new_total_pages
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log(f"[API] 重新获取列表失败: {str(e)}")
|
self.log(f"[API] 获取第{current_page}页列表失败: {str(e)}")
|
||||||
break
|
break
|
||||||
|
|
||||||
report_progress(force=True)
|
report_progress(force=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user