From 79beed724f3e845bde6c68cb2adfbe4bac33195e Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Sun, 23 Dec 2012 18:20:33 +0100 Subject: [PATCH] Fix a performance issue on prettifying SQL queries that makes pgBagder several time slower that usual to generate the HTML output. Thanks to Vincent Laborie for the report. --- pgbadger | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pgbadger b/pgbadger index efe59b3..aa2b4d4 100755 --- 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); -- 2.40.0