diff --git a/api_v1_rss.php b/api_v1_rss.php index ac132b0..d127682 100644 --- a/api_v1_rss.php +++ b/api_v1_rss.php @@ -124,11 +124,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } } - // Check if already exists - $stmt_check = db()->prepare("SELECT id FROM messages WHERE channel_id = ? AND rss_guid = ?"); + // Check if already exists in processed items (prevents re-posting if deleted by retention policy) + $stmt_check = db()->prepare("SELECT id FROM rss_processed_items WHERE channel_id = ? AND rss_guid = ?"); $stmt_check->execute([$channel_id, $guid]); if ($stmt_check->fetch()) continue; + // Insert into processed items first to be safe + $stmt_processed = db()->prepare("INSERT IGNORE INTO rss_processed_items (channel_id, rss_guid) VALUES (?, ?)"); + $stmt_processed->execute([$channel_id, $guid]); + // Insert as message from a special "RSS Bot" user or system $stmt_bot = db()->prepare("SELECT id FROM users WHERE username = 'RSS Bot' AND is_bot = 1"); $stmt_bot->execute(); diff --git a/db/migrations/20260217_rss_processed_items.sql b/db/migrations/20260217_rss_processed_items.sql new file mode 100644 index 0000000..a21a838 --- /dev/null +++ b/db/migrations/20260217_rss_processed_items.sql @@ -0,0 +1,9 @@ +-- Migration: Track processed RSS items to prevent re-posting after they are deleted by retention policy +CREATE TABLE IF NOT EXISTS rss_processed_items ( + id INT AUTO_INCREMENT PRIMARY KEY, + channel_id INT NOT NULL, + rss_guid VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + UNIQUE KEY idx_channel_guid (channel_id, rss_guid), + FOREIGN KEY (channel_id) REFERENCES channels(id) ON DELETE CASCADE +); diff --git a/requests.log b/requests.log index af17a36..300b96d 100644 --- a/requests.log +++ b/requests.log @@ -413,3 +413,7 @@ 2026-02-16 23:46:41 - GET /index.php?server_id=1&channel_id=12 - POST: [] 2026-02-16 23:47:02 - GET /index.php?server_id=1&channel_id=12 - POST: [] 2026-02-16 23:48:40 - GET /index.php?server_id=1&channel_id=12 - POST: [] +2026-02-17 00:21:52 - GET /?fl_project=38443 - POST: [] +2026-02-17 00:22:06 - GET /index.php?server_id=1&channel_id=12 - POST: [] +2026-02-17 00:22:15 - GET /index.php?server_id=1&channel_id=12 - POST: [] +2026-02-17 00:22:19 - GET /index.php?server_id=1&channel_id=12 - POST: []