From 0a2b00e763f06d667e8b296f77873ddcb4724bf4 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 9 Nov 2009 15:00:37 +0100 Subject: [PATCH] Optimize SQL to determine file selection with directories. It is enabled for ascii path. --- gui/bweb/cgi/bresto.pl | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gui/bweb/cgi/bresto.pl b/gui/bweb/cgi/bresto.pl index a0b217cb42..9624436a08 100755 --- a/gui/bweb/cgi/bresto.pl +++ b/gui/bweb/cgi/bresto.pl @@ -912,11 +912,21 @@ sub fill_table_for_restore FROM File WHERE FileId IN ($fileid))"; } - # using this is not good because the sql engine doesn't know - # what LIKE will use. It will be better to get Path% in perl - # but it doesn't work with accents... :( foreach my $dirid (@dirid) { - push @union, " + my $p = $bvfs->get_path($dirid); + if ($p =~ m!^[a-z0-9/\-_\s,.;:*={}()\[\]\!?]+$!i) { + push @union, " + (SELECT File.JobId, File.FileIndex, File.FilenameId, File.PathId $FileId + FROM Path JOIN File USING (PathId) + WHERE Path.Path LIKE '$p%' + AND File.JobId IN ($inclause))"; + + } else { + # using this is not good because the sql engine doesn't know + # what LIKE will use. It will be better to get Path% in perl + # but it doesn't work with accents... :( + + push @union, " (SELECT File.JobId, File.FileIndex, File.FilenameId, File.PathId $FileId FROM Path JOIN File USING (PathId) WHERE Path.Path LIKE @@ -924,6 +934,7 @@ sub fill_table_for_restore WHERE PathId = $dirid ) AND File.JobId IN ($inclause))"; + } } return unless scalar(@union); -- 2.39.5