From 841b5d3961f31277c424a4432fc51f0ac4bf093f Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sun, 6 Sep 2009 22:45:51 +0000 Subject: Bug 176002: Move duplicate statistics into the db Patch by Max Kanat-Alexander r=LpSolit, a=LpSolit --- collectstats.pl | 80 --------------------------------------------------------- 1 file changed, 80 deletions(-) (limited to 'collectstats.pl') diff --git a/collectstats.pl b/collectstats.pl index e550c1613..5f9b4eef3 100755 --- a/collectstats.pl +++ b/collectstats.pl @@ -33,12 +33,9 @@ use strict; use lib qw(. lib); -use AnyDBM_File; -use IO::Handle; use List::Util qw(first); use Cwd; - use Bugzilla; use Bugzilla::Constants; use Bugzilla::Error; @@ -160,8 +157,6 @@ my $tend = time; # Uncomment the following line for performance testing. #print "Total time taken " . delta_time($tstart, $tend) . "\n"; -&calculate_dupes(); - CollectSeriesData(); sub check_data_dir { @@ -299,81 +294,6 @@ sub get_old_data { return @data; } -sub calculate_dupes { - my $dbh = Bugzilla->dbh; - my $rows = $dbh->selectall_arrayref("SELECT dupe_of, dupe FROM duplicates"); - - my %dupes; - my %count; - my $key; - my $changed = 1; - - my $today = &today_dash; - - # Save % count here in a date-named file - # so we can read it back in to do changed counters - # First, delete it if it exists, so we don't add to the contents of an old file - my $datadir = bz_locations()->{'datadir'}; - - if (my @files = <$datadir/duplicates/dupes$today*>) { - map { trick_taint($_) } @files; - unlink @files; - } - - dbmopen(%count, "$datadir/duplicates/dupes$today", 0644) || die "Can't open DBM dupes file: $!"; - - # Create a hash with key "a bug number", value "bug which that bug is a - # direct dupe of" - straight from the duplicates table. - foreach my $row (@$rows) { - my ($dupe_of, $dupe) = @$row; - $dupes{$dupe} = $dupe_of; - } - - # Total up the number of bugs which are dupes of a given bug - # count will then have key = "bug number", - # value = "number of immediate dupes of that bug". - foreach $key (keys(%dupes)) - { - my $dupe_of = $dupes{$key}; - - if (!defined($count{$dupe_of})) { - $count{$dupe_of} = 0; - } - - $count{$dupe_of}++; - } - - # Now we collapse the dupe tree by iterating over %count until - # there is no further change. - while ($changed == 1) - { - $changed = 0; - foreach $key (keys(%count)) { - # if this bug is actually itself a dupe, and has a count... - if (defined($dupes{$key}) && $count{$key} > 0) { - # add that count onto the bug it is a dupe of, - # and zero the count; the check is to avoid - # loops - if ($count{$dupes{$key}} != 0) { - $count{$dupes{$key}} += $count{$key}; - $count{$key} = 0; - $changed = 1; - } - } - } - } - - # Remove the values for which the count is zero - foreach $key (keys(%count)) - { - if ($count{$key} == 0) { - delete $count{$key}; - } - } - - dbmclose(%count); -} - # This regenerates all statistics from the database. sub regenerate_stats { my ($dir, $product, $bug_resolution, $bug_status, $removed) = @_; -- cgit v1.2.3-24-g4f1b