diff --git a/app/services/pipeline.py b/app/services/pipeline.py index b5049fe..ac4b829 100644 --- a/app/services/pipeline.py +++ b/app/services/pipeline.py @@ -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)