]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/Schedulers.pl
- irctextcounter: ORDER by counter, not nick!
[infobot.git] / src / IRC / Schedulers.pl
index 4566df6872f2047dba1554a33480900108d3858f..7d79eb6e0a6cdd6f46dc0791a4a51e474a079738 100644 (file)
@@ -37,7 +37,7 @@ sub setupSchedulers {
     &freshmeatLoop(2);
     &kernelLoop(2);
     &wingateWriteFile(2);
-    &factoidCheck(2);
+    &factoidCheck(1);
     &newsFlush(1);
 
 #    my $count = map { exists $sched{$_}{TIME} } keys %sched;
@@ -261,7 +261,7 @@ sub seenFlushOld {
        my $time = time();
 
        foreach (keys %seen) {
-           my $delta_time = $time - &dbGet("seen", "NULL", $_, "time");
+           my $delta_time = $time - &dbGet("seen", "time", "nick='$_'");
            next unless ($delta_time > $max_time);
 
            &DEBUG("seenFlushOld: ".&Time2String($delta_time) );
@@ -281,8 +281,7 @@ sub newsFlush {
        return if ($_[0] eq "2");       # defer.
     }
 
-    if (&ChanConfList("news")) {
-    } else {
+    if (!&ChanConfList("news")) {
        &DEBUG("newsFlush: news disabled? (chan => $chan)");
        return;
     }
@@ -294,7 +293,10 @@ sub newsFlush {
        my $i           = 0;
        my $total       = scalar(keys %{ $::news{$chan} });
 
-       &DEBUG("newsFlush: chan => $chan");
+       if (!$total) {
+           delete $::news{$chan};
+           next;
+       }
 
        foreach $item (keys %{ $::news{$chan} }) {
            my $t = $::news{$chan}{$item}{Expire};
@@ -320,7 +322,7 @@ sub newsFlush {
            $i++;
        }
 
-       &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.");
+       &status("NEWS (newsflush) {$chan}: deleted [$i/$total] news entries.") if ($i);
        $none{$chan} = 1 if ($total == $i);
     }
 
@@ -341,12 +343,14 @@ sub newsFlush {
            delete $::newsuser{$chan}{$_};
            $duser++;
        }
+
+       my $i = scalar(keys %{ $::newsuser{$chan} });
+       delete $::newsuser{$chan} unless ($i);
     }
 
     if ($delete or $duser) {
-       &DEBUG("newsF: Writing news.");
        &News::writeNews();
-       &status("NEWS (newsflush) deleted: $delete news entries; $duser user cache.");
+       &status("NewsFlush: deleted: $delete news entries; $duser user cache.");
     }
 }
 
@@ -367,7 +371,7 @@ sub chanlimitCheck {
 
        if (scalar keys %netsplitservers) {
            if (defined $limit) {
-               &DEBUG("chanlimit: removing it for $chan.");
+               &status("chanlimit: netsplit; removing it for $chan.");
                &rawout("MODE $chan -l");
                $cache{chanlimitChange}{$chan} = time();
            }
@@ -395,13 +399,13 @@ sub chanlimitCheck {
        delete $cache{warn}{chanlimit}{$chan};
 
        if (!defined $limit) {
-           &status("ChanLimit: setting for first time or from netsplit, for $chan");
+           &status("chanLimit: setting for first time or from netsplit, for $chan");
        }
 
        if (exists $cache{chanlimitChange}{$chan}) {
            my $delta = time() - $cache{chanlimitChange}{$chan};
            if ($delta < $interval*60) {
-               &DEBUG("not going to change chanlimit! ($delta<$interval*60)");
+               &DEBUG("chanLimit: not going to change chanlimit! ($delta<$interval*60)");
                return;
            }
        }
@@ -419,38 +423,58 @@ sub netsplitCheck {
        return if ($_[0] eq "2");
     }
 
-    &DEBUG("running netsplitCheck...");
+    $cache{'netsplitCache'}++;
+    &DEBUG("running netsplitCheck... $cache{netsplitCache}");
+
+    if (!scalar %netsplit and scalar %netsplitservers) {
+       &DEBUG("nsC: !hash netsplit but hash netsplitservers <- removing!");
+       undef %netsplitservers;
+       return;
+    }
 
+    # well... this shouldn't happen since %netsplit code does it anyway.
     foreach $s1 (keys %netsplitservers) {
-       &DEBUG("nsC: s1 => $s1");
 
        foreach $s2 (keys %{ $netsplitservers{$s1} }) {
            my $delta = time() - $netsplitservers{$s1}{$s2};
-           &DEBUG("nss{$s1}{$s2} = $delta");
 
-           if (time() - $netsplitservers{$s1}{$s2} > 3600) {
+           if ($delta > 60*30) {
                &status("netsplit between $s1 and $s2 appears to be stale.");
                delete $netsplitservers{$s1}{$s2};
+               &chanlimitCheck();
            }
        }
+
+       my $i = scalar(keys %{ $netsplitservers{$s1} });
+       delete $netsplitservers{$s1} unless ($i);
     }
 
     # %netsplit hash checker.
     my $count  = scalar keys %netsplit;
+    my $delete = 0;
     foreach (keys %netsplit) {
-       if (&IsNickInAnyChan($_)) {
-           &DEBUG("netsplitC: $_ is in some chan; removing from netsplit list.");
+       if (&IsNickInAnyChan($_)) {     # why would this happen?
+#          &DEBUG("nsC: $_ is in some chan; removing from netsplit list.");
            delete $netsplit{$_};
+           $delete++;
            next;
        }
-       next unless (time() - $netsplit{$_} > 60*10);
 
-       &DEBUG("netsplitC: $_ didn't come back from netsplit; removing from netsplit list.");
+       next unless (time() - $netsplit{$_} > 60*15);
+
+       $delete++;
        delete $netsplit{$_};
     }
 
-    &DEBUG("nsC: netsplitservers: ".scalar(keys %netsplitservers) );
-    &DEBUG("nsC: netsplit: ".scalar(keys %netsplit) );
+    if ($delete) {
+       my $j = scalar(keys %netsplit);
+       &DEBUG("nsC: removed from netsplit list: (before: $count; after: $j)");
+    }
+
+    if (!scalar %netsplit and scalar %netsplitservers) {
+       &DEBUG("nsC: ok hash netsplit is NULL; purging hash netsplitservers");
+       undef %netsplitservers;
+    }
 
     if ($count and !scalar keys %netsplit) {
        &DEBUG("nsC: netsplit is hopefully gone. reinstating chanlimit check.");
@@ -502,8 +526,8 @@ sub seenFlush {
 
     if ($param{'DBType'} =~ /^mysql|pg|postgres/i) {
        foreach $nick (keys %seencache) {
-           my $retval = &dbReplace("seen", "nick", $nick, (
-###                    "nick" => $seencache{$nick}{'nick'},
+           my $retval = &dbReplace("seen", (
+                       "nick" => $seencache{$nick}{'nick'},
                        "time" => $seencache{$nick}{'time'},
                        "host" => $seencache{$nick}{'host'},
                        "channel" => $seencache{$nick}{'chan'},
@@ -518,7 +542,7 @@ sub seenFlush {
            ### old code.
            ###
 
-           my $exists = &dbGet("seen","nick", $nick, "nick");
+           my $exists = &dbGet("seen", "nick", "nick='$nick'");
 
            if (defined $exists and $exists) {
                &dbUpdate("seen", "nick", $nick, (
@@ -567,7 +591,7 @@ sub seenFlush {
        &DEBUG("seenFlush: NO VALID FACTOID SUPPORT?");
     }
 
-    &status("Flushed $flushed seen entries.")          if ($flushed);
+    &status("Seen: Flushed $flushed entries.") if ($flushed);
     &VERB(sprintf("  new seen: %03.01f%% (%d/%d)",
        $stats{'new'}*100/($stats{'count_old'} || 1),
        $stats{'new'}, ( $stats{'count_old'} || 1) ), 2) if ($stats{'new'});
@@ -716,11 +740,6 @@ sub ircCheck {
        delete $channels{''};
     }
 
-    &DEBUG("ircstats...");
-    &DEBUG("  pubsleep: $pubsleep");
-    &DEBUG("  msgsleep: $msgsleep");
-    &DEBUG("  notsleep: $notsleep");
-
     ### USER FILE.
     if ($utime_userfile > $wtime_userfile and time() - $wtime_userfile > 3600) {
        &writeUserFile();
@@ -1025,12 +1044,17 @@ sub wingateWriteFile {
 
 sub factoidCheck {
     if (@_) {
-       &ScheduleThis(1440, "factoidCheck");
+       &ScheduleThis(720, "factoidCheck");
        return if ($_[0] eq "2");       # defer.
     }
 
     my @list   = &searchTable("factoids", "factoid_key", "factoid_key", " #DEL#");
-    my $stale  = &getChanConfDefault("factoidDeleteDelay", 30) *60*60*24;
+    my $stale  = &getChanConfDefault("factoidDeleteDelay", 14) *60*60*24;
+    if ($stale < 1) {
+       # disable it since it's "illegal".
+       return;
+    }
+
     my $time   = time();
 
     foreach (@list) {
@@ -1045,7 +1069,7 @@ sub factoidCheck {
                }
            }
 
-           &WARN("old cruft (no time): $_");
+           &WARN("del factoid: old cruft (no time): $_");
            &delFactoid($_);
            next;
        }
@@ -1054,11 +1078,11 @@ sub factoidCheck {
 
        my $fix = $_;
        $fix =~ s/ #DEL#$//g;
-       &DEBUG("safedel: Removing $fix ($_) for good.");
+       my $agestr = &Time2String($time - $age);
+       &status("safedel: Removing '$_' for good. [$agestr old]");
 
        &delFactoid($_);
     }
-
 }
 
 sub dccStatus {
@@ -1145,20 +1169,20 @@ sub mkBackup {
     my $backup         = 0;
 
     if (! -f $file) {
-       &WARN("mkB: file '$file' does not exist.");
+       &VERB("mkB: file '$file' does not exist.",2);
        return;
     }
 
+    my $age    = "New";
     if ( -e "$file~" ) {
-       $backup++ if ((stat $file)[9] - (stat "$file~")[9] > $time);
+       $backup++       if ((stat $file)[9] - (stat "$file~")[9] > $time);
+       my $delta       = time() - (stat "$file~")[9];
+       $age            = &Time2String($delta);
     } else {
        $backup++;
     }
-    return unless ($backup);
 
-    # should delta be time(file) - time(file~)?
-    my $delta  = time() - (stat "$file~")[9];
-    my $age    = &Time2String($delta);
+    return unless ($backup);
 
     ### TODO: do internal copying.
     &status("Backup: $file ($age)");