fix: 存库前先标记 keyword_matched,修复历史数据全为 false 的问题

pipeline 原来先存库再过滤,导致 keyword_matched 永远是 False。
改为先标记再存库,最新公告查询才能正确区分两个来源。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-12 17:51:00 +08:00
parent dc3ca1f76c
commit c01a3d427b
+11 -7
View File
@@ -20,24 +20,28 @@ class PostCrawlPipeline:
if config.dedup_enabled:
announcements = dedup_by_hash(announcements)
# 2. Store to database
# 2. 先标记 keyword_matched,再存库
if config.filter_enabled and config.keywords:
for a in announcements:
a["keyword_matched"] = self._match_keywords(a, config.keywords)
# 3. Store to database
stored = await self._save_to_db(announcements)
result.stored = stored
to_notify = announcements
# 3. Filter
# 4. Filter
if config.filter_enabled and config.keywords:
before = len(to_notify)
to_notify = [a for a in to_notify
if self._match_keywords(a, config.keywords)]
to_notify = [a for a in to_notify if a.get("keyword_matched")]
result.filtered = before - len(to_notify)
# 4. Skip already-notified
# 5. Skip already-notified
if to_notify:
to_notify = await self._exclude_sent(to_notify)
# 5. Notify
# 6. Notify
if config.notify_mode == "all":
result.notified = await self._send_notifications(to_notify)
elif config.notify_mode == "filtered":
@@ -46,7 +50,7 @@ class PostCrawlPipeline:
elif not config.filter_enabled:
result.notified = await self._send_notifications(to_notify)
# 6. Mark sent
# 7. Mark sent
if config.mark_sent and result.notified > 0:
await self._mark_sent(to_notify)