Bugzilla – Attachment 123490 Details for
Bug 22690
Merging records with many items too slow (Elasticsearch)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22690: (QA follow-up) Move adopt_items_from_biblios to Koha::Items
Bug-22690-QA-follow-up-Move-adoptitemsfrombiblios-.patch (text/plain), 7.19 KB, created by
Martin Renvoize (ashimema)
on 2021-08-05 13:29:04 UTC
(
hide
)
Description:
Bug 22690: (QA follow-up) Move adopt_items_from_biblios to Koha::Items
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-08-05 13:29:04 UTC
Size:
7.19 KB
patch
obsolete
>From 33463ed359eb65c495f33679eca2fefd9177a4be Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 22 Jul 2021 10:13:42 +0100 >Subject: [PATCH] Bug 22690: (QA follow-up) Move adopt_items_from_biblios to > Koha::Items > >This patch moves the Koha::Biblio->adopt_items_from_biblio method to the >Koha::Items set class and updates all calls from >Biblio2->adopt_items_from_biblio(Biblio1) to Biblio->items->move_to_biblio(Biblio2) >--- > Koha/Biblio.pm | 24 ---------------------- > Koha/Items.pm | 22 ++++++++++++++++++++ > cataloguing/merge.pl | 4 ++-- > t/db_dependent/Koha/Biblio.t | 24 +--------------------- > t/db_dependent/Koha/Items.t | 24 +++++++++++++++++++++- > t/db_dependent/Koha/SearchEngine/Indexer.t | 4 ++-- > 6 files changed, 50 insertions(+), 52 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 4f1fabc98a..26ee7abd96 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -39,7 +39,6 @@ use Koha::CirculationRules; > use Koha::Item::Transfer::Limits; > use Koha::Items; > use Koha::Libraries; >-use Koha::SearchEngine::Indexer; > use Koha::Suggestions; > use Koha::Subscriptions; > >@@ -953,29 +952,6 @@ sub get_marc_host { > } > } > >-=head3 adopt_items_from_biblio >- >-$biblio->adopt_items_from_biblio($from_biblio); >- >-Move items from the given biblio to this one. >- >-=cut >- >-sub adopt_items_from_biblio { >- my ( $self, $from_biblio ) = @_; >- >- my $items = $from_biblio->items; >- if ($items) { >- while (my $item = $items->next()) { >- $item->move_to_biblio($self, { skip_record_index => 1 }); >- } >- my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >- $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" ); >- $indexer->index_records( $from_biblio->biblionumber, "specialUpdate", "biblioserver" ); >- } >-} >- >- > =head2 Internal methods > > =head3 type >diff --git a/Koha/Items.pm b/Koha/Items.pm >index 2643223d3b..834ac18230 100644 >--- a/Koha/Items.pm >+++ b/Koha/Items.pm >@@ -26,6 +26,8 @@ use Koha::Item; > > use base qw(Koha::Objects); > >+use Koha::SearchEngine::Indexer; >+ > =head1 NAME > > Koha::Items - Koha Item object set class >@@ -108,6 +110,26 @@ sub filter_out_lost { > return $self->search( $params ); > } > >+=head3 move_to_biblio >+ >+ $items->move_to_biblio($to_biblio); >+ >+Move items to a given biblio. >+ >+=cut >+ >+sub move_to_biblio { >+ my ( $self, $to_biblio ) = @_; >+ >+ while (my $item = $self->next()) { >+ $item->move_to_biblio($to_biblio, { skip_record_index => 1 }); >+ } >+ my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" ); >+ $indexer->index_records( $from_biblio->biblionumber, "specialUpdate", "biblioserver" ); >+} >+ >+ > =head2 Internal methods > > =head3 _type >diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl >index 47227178b6..fca94ca4d5 100755 >--- a/cataloguing/merge.pl >+++ b/cataloguing/merge.pl >@@ -96,7 +96,7 @@ if ($merge) { > my $biblio = Koha::Biblios->find($ref_biblionumber); > foreach my $biblionumber (@biblionumbers) { > my $from_biblio = Koha::Biblios->find($biblionumber); >- $biblio->adopt_items_from_biblio($from_biblio); >+ $from_biblio->items->move_to_biblio($biblio); > $from_biblio->article_requests->update({ biblionumber => $ref_biblionumber }, { no_triggers => 1 }); > } > >@@ -161,7 +161,7 @@ if ($merge) { > # Moving suggestions > $sth_suggestions->execute($ref_biblionumber, $biblionumber); > >- # Moving orders (orders linked to items of frombiblio have already been moved by adopt_items_from_biblio) >+ # Moving orders (orders linked to items of frombiblio have already been moved by move_to_biblio) > my @allorders = GetOrdersByBiblionumber($biblionumber); > foreach my $myorder (@allorders) { > $myorder->{'biblionumber'} = $ref_biblionumber; >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index c978672aca..83de0634c6 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 15; >+use Test::More tests => 14; > > use C4::Biblio qw( AddBiblio ModBiblio ); > use Koha::Database; >@@ -637,25 +637,3 @@ subtest 'get_marc_notes() UNIMARC tests' => sub { > > $schema->storage->txn_rollback; > }; >- >-subtest 'adopt_items_from_biblio() tests' => sub { >- >- plan tests => 2; >- >- $schema->storage->txn_begin; >- >- my $biblio1 = $builder->build_sample_biblio; >- my $biblio2 = $builder->build_sample_biblio; >- my $item1 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber }); >- my $item2 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber }); >- >- $biblio2->adopt_items_from_biblio($biblio1); >- >- $item1->discard_changes; >- $item2->discard_changes; >- >- is($item1->biblionumber, $biblio2->biblionumber, "Item 1 moved"); >- is($item2->biblionumber, $biblio2->biblionumber, "Item 2 moved"); >- >- $schema->storage->txn_rollback; >-}; >diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t >index bad4256d6a..d743402b1a 100755 >--- a/t/db_dependent/Koha/Items.t >+++ b/t/db_dependent/Koha/Items.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 14; >+use Test::More tests => 15; > > use Test::MockModule; > use Test::Exception; >@@ -1725,3 +1725,25 @@ subtest 'filter_out_lost() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'move_to_biblio() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $biblio1 = $builder->build_sample_biblio; >+ my $biblio2 = $builder->build_sample_biblio; >+ my $item1 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber }); >+ my $item2 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber }); >+ >+ $biblio1->items->move_to_biblio($biblio2); >+ >+ $item1->discard_changes; >+ $item2->discard_changes; >+ >+ is($item1->biblionumber, $biblio2->biblionumber, "Item 1 moved"); >+ is($item2->biblionumber, $biblio2->biblionumber, "Item 2 moved"); >+ >+ $schema->storage->txn_rollback; >+ >+}; >diff --git a/t/db_dependent/Koha/SearchEngine/Indexer.t b/t/db_dependent/Koha/SearchEngine/Indexer.t >index 9ee997c263..22ff468571 100755 >--- a/t/db_dependent/Koha/SearchEngine/Indexer.t >+++ b/t/db_dependent/Koha/SearchEngine/Indexer.t >@@ -184,8 +184,8 @@ subtest 'Test indexer calls' => sub { > } undef, "index_records is not called for $engine when moving an item to another biblio (Item->move_to_biblio) if skip_record_index passed"; > > warnings_are{ >- $biblio2->adopt_items_from_biblio($biblio); >- } [$engine,"Koha::Biblio",$engine,"Koha::Biblio"], "index_records is called for both biblios for $engine when adopting items (Biblio->adopt_items_from_biblio)"; >+ $biblio->items->move_to_biblio($biblio2); >+ } [$engine,"Koha::Biblio",$engine,"Koha::Biblio"], "index_records is called for both biblios for $engine when adopting items (Biblio->items->move_to_biblio(Biblio)"; > > $builder->build({ > source => 'Issue', >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22690
:
90061
|
90115
|
90116
|
92828
|
94505
|
97696
|
98143
|
98210
|
98211
|
99376
|
99379
|
100316
|
104796
|
104797
|
104871
|
105445
|
106144
|
108777
|
109694
|
110991
|
110994
|
111196
|
111207
|
111236
|
111237
|
112100
|
112184
|
112567
|
112569
|
112754
|
113308
|
113309
|
113941
|
113942
|
113967
|
113968
|
118226
|
118227
|
118229
|
118231
|
118391
|
119433
|
119434
|
120820
|
120821
|
120852
|
120853
|
121389
|
121392
|
121474
|
121516
|
121517
|
121518
|
121519
|
121520
|
122846
|
122847
|
122848
|
122849
|
122850
|
122886
|
122887
|
122888
|
122889
|
122890
|
122936
|
122938
|
122939
|
123029
|
123030
|
123031
|
123032
|
123033
|
123034
|
123035
|
123036
|
123037
|
123038
|
123039
|
123040
|
123041
|
123042
|
123044
|
123062
|
123481
|
123482
|
123483
|
123484
|
123485
|
123486
|
123487
|
123488
|
123489
| 123490 |
123491
|
123492
|
123493
|
123494
|
123495
|
123496
|
123497
|
124176
|
124188
|
124257