From 6551bebd939aefb3a4e6c59d3bee83c311cd842d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 1 Aug 2016 13:46:49 +0100 Subject: [PATCH] Bug 17009: Speed up the framework duplication MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To duplicate frameworks, the code retrieve all the subfields, then execute 1 insert per subfield. It's unnecessary slow, we can use the DBMS to do it. Test plan: Create a new framework and duplicate the structure of another framework. Signed-off-by: Marc Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall (cherry picked from commit 739eaa82e8b52a1ef83e995badc7ddfa3a32e3fc) Signed-off-by: Frédéric Demians --- admin/marctagstructure.pl | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl index 0f27ac0692..2b4f2a194c 100755 --- a/admin/marctagstructure.pl +++ b/admin/marctagstructure.pl @@ -344,18 +344,11 @@ sub StringSearch { sub duplicate_framework { my ($newframeworkcode,$oldframeworkcode) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where frameworkcode=?"); - $sth->execute($oldframeworkcode); - my $sth_insert = $dbh->prepare("insert into marc_tag_structure (tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, frameworkcode) values (?,?,?,?,?,?,?)"); - while ( my ($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value) = $sth->fetchrow) { - $sth_insert->execute($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value,$newframeworkcode); - } + $dbh->do(q|INSERT INTO marc_tag_structure (tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, frameworkcode) + SELECT tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value, ? from marc_tag_structure where frameworkcode=?|, undef, $newframeworkcode, $oldframeworkcode ); - $sth = $dbh->prepare("select frameworkcode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,authtypecode,value_builder,seealso,hidden from marc_subfield_structure where frameworkcode=?"); - $sth->execute($oldframeworkcode); - $sth_insert = $dbh->prepare("insert into marc_subfield_structure (frameworkcode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,authtypecode,value_builder,seealso,hidden) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - while ( my ($frameworkcode, $tagfield, $tagsubfield, $liblibrarian, $libopac, $repeatable, $mandatory, $kohafield, $tab, $authorised_value, $thesaurus_category, $value_builder, $seealso,$hidden) = $sth->fetchrow) { - $sth_insert->execute($newframeworkcode, $tagfield, $tagsubfield, $liblibrarian, $libopac, $repeatable, $mandatory, $kohafield, $tab, $authorised_value, $thesaurus_category, $value_builder, $seealso, $hidden); - } + $dbh->do(q|INSERT INTO marc_subfield_structure (frameworkcode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,authtypecode,value_builder,seealso,hidden) + SELECT ?,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,authtypecode,value_builder,seealso,hidden from marc_subfield_structure where frameworkcode=? + |, undef, $newframeworkcode, $oldframeworkcode ); } -- 2.39.5