diff feeds.tcl @ 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 9380535b8f12
children 299cdd79b7ee
line wrap: on
line diff
--- 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 {