From f78d4c2158439fea62c73b8aa9568f87842b09f7 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Thu, 29 May 2025 18:03:44 +0200 Subject: [PATCH] Refactor getting raw headers. Signed-off-by: Thomas Hochstein --- bin/gatherstats.pl | 46 +++++++++++++++++++++++++++++++--------------- doc/ChangeLog | 1 + 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/bin/gatherstats.pl b/bin/gatherstats.pl index ca90cc7..6118a70 100755 --- a/bin/gatherstats.pl +++ b/bin/gatherstats.pl @@ -261,21 +261,7 @@ sub HostStats { my (%Postings,$DBQuery); - if (!$MID) { - # get raw header data from raw table for given month - $DBQuery = $DBHandle->prepare(sprintf("SELECT newsgroups,headers FROM %s ". - "WHERE day LIKE ? AND NOT disregard", - $DBRaw)); - $DBQuery->execute($Month.'-%') - or &Bleat(2,sprintf("Can't get hosts data for %s from %s: ". - "$DBI::errstr\n",$Month,$DBRaw)); - } else { - $DBQuery = $DBHandle->prepare(sprintf("SELECT newsgroups,headers FROM %s ". - "WHERE mid = ?", $DBRaw)); - $DBQuery->execute($MID) - or &Bleat(2,sprintf("Can't get hosts data for %s from %s: ". - "$DBI::errstr\n",$MID,$DBRaw)); - } + $DBQuery = GetHeaders($DBHandle,$DBRaw,$Month,$MID); ### ---------------------------------------------- print "----- HostStats -----\n" if $Debug; @@ -372,6 +358,36 @@ sub HostStats { }; }; +sub GetHeaders { +### ---------------------------------------------------------------------------- +### get (newsgroups and) raw headers from database +### IN : $DBHandle : database handle +### $DBRaw : database table for raw data (to read from) +### $Month : current month to do +### $MID : specific Message-ID to fetch (testing purposes) +### OUT: DBI statement handle + my ($DBHandle,$DBRaw,$Month,$MID) = @_; + + my $DBQuery; + + if (!$MID) { + # get raw header data from raw table for given month + $DBQuery = $DBHandle->prepare(sprintf("SELECT newsgroups,headers FROM %s ". + "WHERE day LIKE ? AND NOT disregard", + $DBRaw)); + $DBQuery->execute($Month.'-%') + or &Bleat(2,sprintf("Can't get header data for %s from %s: ". + "$DBI::errstr\n",$Month,$DBRaw)); + } else { + $DBQuery = $DBHandle->prepare(sprintf("SELECT newsgroups,headers FROM %s ". + "WHERE mid = ?", $DBRaw)); + $DBQuery->execute($MID) + or &Bleat(2,sprintf("Can't get header data for %s from %s: ". + "$DBI::errstr\n",$MID,$DBRaw)); + } + return $DBQuery; +} + sub CheckTLH { ### ---------------------------------------------------------------------------- ### count newsgroups from legal TLH(s) diff --git a/doc/ChangeLog b/doc/ChangeLog index 9f248cc..3f46f78 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,7 @@ NewsStats 0.4.0 (unreleased) * Reformat $Conf{TLH} for GroupStats only. * Extract TLH check from HostStats to subroutine, fix no-op check. + * Extract getting raw headers from HostStats to subroutine. NewsStats 0.3.0 (2025-05-18) * Extract GroupStats (in gatherstats) to subroutine.