~bgo-maintainers/bugzilla-traceparser/3.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl -w

use strict;
use warnings;
use lib qw(. lib extensions/traceparser/lib);
use Bugzilla;
use Bugzilla::Install::Util qw(indicate_progress);
use TraceParser::Trace;

my $dbh = Bugzilla->dbh;

print "Re-parsing traces...\n";
my $total = $dbh->selectrow_array('SELECT COUNT(*) FROM trace');
    
if ($dbh->isa('Bugzilla::DB::Mysql')) {
    $dbh->{'mysql_use_result'} = 1;
}
    
my $sth = $dbh->prepare('SELECT id,trace_text FROM trace ORDER BY id');
$sth->execute();
my $count = 0;
my @traces;
while (my ($id, $text) = $sth->fetchrow_array) {
    $count++;
    my $trace = TraceParser::Trace->parse_from_text($text);
    indicate_progress({ current => $count, total => $total, every => 10 });
    $trace->{id} = $id;
    push(@traces, $trace);
}

if ($dbh->isa('Bugzilla::DB::Mysql')) {
    $dbh->{'mysql_use_result'} = 0;
}

$dbh->bz_start_transaction();
print "Updating trace hashes...\n";
$count = 1;
foreach my $trace (@traces) {
    $dbh->do("UPDATE trace SET stack_hash = ?, short_hash = ?, quality = ? 
               WHERE id = ?",
             undef, $trace->{stack_hash}, $trace->{short_hash}, 
             $trace->{quality}, $trace->{id});
    indicate_progress({ current => $count, total => $total, every => 10 });
}
$dbh->bz_commit_transaction();