[livejournal] r17677: LJSV-1150 (Top 10 FAQ hasn't been update...
Committer: ailyin
LJSV-1150 (Top 10 FAQ hasn't been updated in... a long time): clean up FAQ stats before writing to them; we're only calculating top 50 FAQs, so the data about the outsiders are obsolete and are on the way outU trunk/bin/maint/stats.pl U trunk/cgi-bin/statslib.pl
Modified: trunk/bin/maint/stats.pl
===================================================================
--- trunk/bin/maint/stats.pl 2010-11-13 05:12:53 UTC (rev 17676)
+++ trunk/bin/maint/stats.pl 2010-11-13 10:03:21 UTC (rev 17677)
@@ -23,6 +23,7 @@
({ 'type' => "global",
'jobname' => "popfaq",
'statname' => "pop_faq",
+ 'cleanup' => 1,
'handler' =>
sub {
my $db_getter = shift;
Modified: trunk/cgi-bin/statslib.pl
===================================================================
--- trunk/cgi-bin/statslib.pl 2010-11-13 05:12:53 UTC (rev 17676)
+++ trunk/cgi-bin/statslib.pl 2010-11-13 10:03:21 UTC (rev 17677)
@@ -63,6 +63,10 @@
die "Error running '$jobname' handler on global reader."
unless $res;
+ if ($stat->{'cleanup'}) {
+ LJ::Stats::cleanup_stat($stat->{'statname'});
+ }
+
# 2 cases:
# - 'statname' is an arrayref, %res structure is ( 'statname' => { 'arg' => 'val' } )
# - 'statname' is scalar, %res structure is ( 'arg' => 'val' )
@@ -194,6 +198,19 @@
return 1;
}
+sub cleanup_stat {
+ my ($cat) = @_;
+
+ return unless $cat;
+
+ my $dbh = LJ::Stats::get_db('dbh');
+ $dbh->{'RaiseError'} = 1;
+
+ $dbh->do("DELETE FROM stats WHERE statcat=?", undef, $cat);
+
+ return 1;
+}
+
# note the last calctime of a given stat
sub LJ::Stats::save_calc {
my ($jobname, $cid) = @_;
@@ -226,6 +243,8 @@
my ($jobname, $cid) = @_;
return undef unless $jobname;
+ return 1 if $LJ::IS_DEV_SERVER;
+
my $dbr = LJ::Stats::get_db("dbr");
my $calctime = $dbr->selectrow_array("SELECT calctime FROM partialstats " .
"WHERE jobname=? AND clusterid=?",
