From 8d935f7c8d64b668084fc5d4d60458b9edf91b13 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 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. --- admin/marctagstructure.pl | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl index 27d9592..0930453 100755 --- a/admin/marctagstructure.pl +++ b/admin/marctagstructure.pl @@ -344,19 +344,12 @@ 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 ); $cache->clear_from_cache("MarcStructure-0-$newframeworkcode"); $cache->clear_from_cache("MarcStructure-1-$newframeworkcode"); $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode"); -- 2.8.1