changeset 351:0f55bbb7fea3

feeds: Improve safety checks and add new configuration setting.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Nov 2015 13:46:01 +0200
parents 51c08336d7b1
children 19b363586b40
files config.feeds.example feeds.tcl
diffstat 2 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/config.feeds.example	Sun Nov 01 22:05:25 2015 +0200
+++ b/config.feeds.example	Fri Nov 27 13:46:01 2015 +0200
@@ -15,6 +15,12 @@
 set feeds_check_period 5
 
 
+# Limit / number of new feed items allowed to be published
+# after which situation is considered unsynchronized / spam and
+# none of the new items are published.
+set feeds_sync_limit 20
+
+
 # Set channels and feed filters here:
 # "#channel" "feedname|feedname2"
 # feednames can use matching, e.g. "mtv3*" would match all beginning with "mtv3"
--- a/feeds.tcl	Sun Nov 01 22:05:25 2015 +0200
+++ b/feeds.tcl	Fri Nov 27 13:46:01 2015 +0200
@@ -100,19 +100,22 @@
 
 # ------------------------------------------------------------------------
 proc feeds_exec {} {
-  global feeds_dbh feeds_check_period feeds_running
+  global feeds_dbh feeds_check_period feeds_running feeds_sync_limit
 
 #  feeds_log "Timed feed check."
   set oldtime [feeds_check_start]
-  set found 0
   
   set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC"
-  feeds_dbh eval $usql {
-    feeds_msg $utime $ufeed $uurl $utitle
-    set found 1
+  set nresult [feeds_dbh onecolumn "SELECT COUNT(*) FROM feeds WHERE utime > $oldtime"]
+  if {$nresult < $feeds_sync_limit} {
+    feeds_smsg $uchan "$nresult uutta, tod. näk. epäsynkissä. Ignoorataan."
+  } else {
+    feeds_dbh eval $usql {
+      feeds_msg $utime $ufeed $uurl $utitle
+    }
   }
 
-  if {$found} {
+  if {$nresult > 0} {
     feeds_check_end
   }
 
@@ -135,7 +138,7 @@
 
 # ------------------------------------------------------------------------
 proc feeds_pubfetch {unick uhost uhand uchan utext} {
-  global feeds_dbh
+  global feeds_dbh feeds_sync_limit
 #  feeds_log "Manual check invoked on $uchan."
 
   set oldtime [feeds_check_start]
@@ -143,8 +146,8 @@
 
   if {$nresult > 0} {
     feeds_check_end
-    if {$nresult >= 20} {
-      feeds_smsg $uchan "$nresult uutta, tod. näk. epäsynkissä. Ignoorataan."
+    if {$nresult >= $feeds_sync_limit} {
+      feeds_smsg $uchan "$nresult uutta, tod. näk. epäsynkissä. Ignoorataan."
     } else {
       set usql "SELECT feed AS ufeed, title AS utitle, url AS uurl, utime AS utime FROM feeds WHERE utime > $oldtime ORDER BY utime ASC"
       feeds_dbh eval $usql {