Ticket #224: expire-cachecount.patch

File expire-cachecount.patch, 2.6 KB (added by shalligan@…, 15 years ago)
  • expire-quarantine-cache.pl

     
    353353       
    354354        return $expiry_count;
    355355    }
     356    sub count_ham_cache($) {
     357        my($dbh) = @_;
     358        my($select, $sth, @row);
     359        my($ham_count);
     360
     361        $select = "SELECT COUNT(DISTINCT maia_mail_recipients.mail_id) " .
     362                  "FROM maia_mail_recipients " .
     363                  "WHERE maia_mail_recipients.type = 'H' ";
     364       
     365        $sth= $dbh->prepare($select)
     366            or die (sprintf("Maia: [expire_quarantine] Couldn't prepare query: %s", $dbh->errstr));
     367        $sth->execute()
     368            or die (sprintf("Maia: [expire_quarantine] Couldn't execute query: %s", $dbh->errstr));
     369        @row = $sth->fetchrow_array();
     370        $ham_count = $row[0];
     371       
     372        $sth->finish;
     373
     374        return $ham_count;
     375           
     376    }
     377    sub count_q_cache($) {
     378        my($dbh) = @_;
     379        my($select, $sth, @row);
     380        my($q_count);
     381
     382        $select = "SELECT COUNT(DISTINCT maia_mail_recipients.mail_id) " .
     383                  "FROM maia_mail_recipients " .
     384                  "WHERE (maia_mail_recipients.type = 'S' OR " .
     385                       "maia_mail_recipients.type = 'B' OR " .
     386                       "maia_mail_recipients.type = 'F' OR " .
     387                       "maia_mail_recipients.type = 'V') ";
     388
     389        $sth= $dbh->prepare($select)
     390            or die (sprintf("Maia: [expire_quarantine] Couldn't prepare query: %s", $dbh->errstr));
     391        $sth->execute()
     392            or die (sprintf("Maia: [expire_quarantine] Couldn't execute query: %s", $dbh->errstr));
     393        @row = $sth->fetchrow_array();
     394        $q_count = $row[0];
     395
     396        $sth->finish;
     397
     398        return $q_count;
     399
     400    }
    356401    # Read the database configuration file into memory once
    357402    open CONFIGFILE, "<" . $cfg
    358403        or die ("Maia: [expire-quarantine-cache] Unable to open $cfg\n");
     
    374419    my $hcount = expire_ham_cache($dbh);
    375420    my $cleanup = expire_orphans($dbh);
    376421    my $strayclean = expire_strays($dbh);
     422    my $curhamcount = count_ham_cache($dbh);
     423    my $curqcount = count_q_cache($dbh);
    377424   
    378425    print $qcount . " quarantined items expired\n";
    379426    print $hcount . " cached ham items expired\n";
     
    383430    if ($strayclean > 0) {
    384431        print $strayclean . " stray items expired - please investigate!\n";
    385432    }
     433    print "\n";
     434    print "Current Cache After Expiration:\n";
     435    print "Quarantined Items: " . $curqcount . "\n";
     436    print "Ham Items: " . $curhamcount . "\n";
    386437    # Disconnect from the database
    387438    $dbh->disconnect;
    388439