From ec90db43112030f0847754ccdfa7d0952f97c4a6 Mon Sep 17 00:00:00 2001 From: vfilippov Date: Tue, 17 Feb 2009 10:30:13 +0000 Subject: [PATCH] Bug 40933 faster way iterating over attachments git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@136 6955db30-a419-402b-8a0d-67ecbb4d7f56 --- Bugzilla/Install/DB.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index daaceb09b..223993fe1 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -2431,16 +2431,26 @@ sub _copy_attachments_thedata_to_attach_data unless $attachdir && -d $attachdir && -w $attachdir; print "Storing attachment data in local directory $attachdir...\n"; print "(This may take a very long time)\n"; - my ($total) = $dbh->selectrow_array("SELECT COUNT(*) FROM attachments"); + my $ids = $dbh->selectcol_arrayref("SELECT attach_id FROM attachments") || []; + my $total = scalar @$ids; my $buf = 16; - my $sth = $dbh->prepare("SELECT attach_id, thedata FROM attachments ORDER BY attach_id LIMIT ?, ?"); + my $sth = undef; + my $sthbind = 0; my ($attachid, $thedata, $hash); my $i = 0; local $| = 1; print "\r$i/$total..."; - while ($i < $total) + while (my @cur = splice @$ids, 0, $buf) { - $sth->execute($i, $buf); + unless ($sth && @cur == $sthbind) + { + $sthbind = @cur; + $sth = $dbh->prepare( + "SELECT attach_id, thedata FROM attachments WHERE attach_id IN (" . + join(",", ("?") x $sthbind) . ")" + ); + } + $sth->execute(@cur); last if !$sth->rows; while (($attachid, $thedata) = $sth->fetchrow_array) {