]> granicus.if.org Git - pgbadger/commitdiff
Fix a performance issue on prettifying SQL queries that makes pgBagder several time...
authorDarold Gilles <gilles@darold.net>
Sun, 23 Dec 2012 17:20:33 +0000 (18:20 +0100)
committerDarold Gilles <gilles@darold.net>
Sun, 23 Dec 2012 17:20:33 +0000 (18:20 +0100)
pgbadger

index efe59b3991740586bd9ab0da94210c2ea3af1055..aa2b4d4e1709c06f20e7ed1eda874f62c35cb101 100755 (executable)
--- a/pgbadger
+++ b/pgbadger
@@ -112,6 +112,7 @@ my $RESRC_URL   = '';
 my $img_format  = 'png';
 my @log_files   = ();
 my %prefix_vars = ();
+my $sql_prettified;
 
 # Do not display data in pie where percentage is lower than this value
 # to avoid label overlapping.
@@ -912,6 +913,10 @@ if ($extension ne 'tsung') {
        } elsif ($extension eq 'binary') {
                &dump_as_binary();
        } else {
+               # Create instance to prettify SQL query
+               if (!$noprettify) {
+                       $sql_prettified = SQL::Beautify->new(keywords => \@pg_keywords);
+               }
                if ($error_only) {
                        &dump_error_as_html();
                } else {
@@ -3689,9 +3694,8 @@ sub highlight_code
 
        # prettify SQL query
        if (!$noprettify) {
-               my $sql = SQL::Beautify->new(keywords => \@pg_keywords);
-               $sql->query($code);
-               $code = $sql->beautify;
+               $sql_prettified->query($code);
+               $code = $sql_prettified->beautify;
        }
 
        return $code if ($nohighlight);