Ver código fonte

seed feed_state from .env at startup — INSERT OR IGNORE, leave existing alone

Lukas Goldschmidt 1 semana atrás
pai
commit
f7f08dc990
1 arquivos alterados com 12 adições e 0 exclusões
  1. 12 0
      news_mcp/mcp_server_fastmcp.py

+ 12 - 0
news_mcp/mcp_server_fastmcp.py

@@ -1148,6 +1148,18 @@ async def _background_refresh_loop():
     )
     logger.info("startup prune_result=%s", prune_result)
 
+    # Seed feed_state from .env — insert missing feeds, leave existing alone
+    feed_urls = [u.strip() for u in NEWS_FEED_URLS.split(",") if u.strip()]
+    if not feed_urls and NEWS_FEED_URL:
+        feed_urls = [NEWS_FEED_URL]
+    with _shared_store._conn() as conn:
+        for url in feed_urls:
+            conn.execute(
+                "INSERT OR IGNORE INTO feed_state(feed_key, last_hash, last_item_count, enabled, updated_at) VALUES(?, '', 0, 1, '')",
+                (url,),
+            )
+    logger.info("startup seeded %d feeds into feed_state", len(feed_urls))
+
     if not NEWS_BACKGROUND_REFRESH_ENABLED:
         return