Bugzilla – Attachment 178617 Details for
Bug 20551
Add option for including deleted records in export_records.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20551: Use iterator for retrieving records to save memory
Bug-20551-Use-iterator-for-retrieving-records-to-s.patch (text/plain), 4.70 KB, created by
David Gustafsson
on 2025-02-24 18:30:58 UTC
(
hide
)
Description:
Bug 20551: Use iterator for retrieving records to save memory
Filename:
MIME Type:
Creator:
David Gustafsson
Created:
2025-02-24 18:30:58 UTC
Size:
4.70 KB
patch
obsolete
>From e523140bc60c8afe7db74abab93fe3d63f6d966c Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >Date: Mon, 24 Feb 2025 14:49:57 +0100 >Subject: [PATCH] Bug 20551: Use iterator for retrieving records to save memory > >--- > Koha/Exporter/Record.pm | 56 ++++++++++++++++++++--------------------- > 1 file changed, 27 insertions(+), 29 deletions(-) > >diff --git a/Koha/Exporter/Record.pm b/Koha/Exporter/Record.pm >index 645d79572f6..f47cfac10e7 100644 >--- a/Koha/Exporter/Record.pm >+++ b/Koha/Exporter/Record.pm >@@ -232,38 +232,40 @@ sub export { > } > > if ( $format eq 'xml' || $format eq 'iso2709' ) { >- my @records; >- @records = map { >- my $record = _get_record_for_export( { %{$params}, record_id => $_ } ); >- $record ? $record : (); >- } @{$record_ids}; >- >- my @deleted_records; >- if ( @{$deleted_record_ids} ) { >- my $resultset = Koha::Database->new()->schema()->resultset('DeletedbiblioMetadata'); >- >- @deleted_records = map { >- my $record = _get_record_for_export( >+ my @record_ids = reverse @{$record_ids}; >+ my @deleted_record_ids = reverse @{$deleted_record_ids}; >+ my $deleted_resultset = Koha::Database->new()->schema()->resultset('DeletedbiblioMetadata'); >+ >+ my $records_iterator = sub { >+ if (@record_ids) { >+ my $record_id = pop(@record_ids); >+ return _get_record_for_export( { %{$params}, record_id => $record_id } ); >+ } >+ elsif (@deleted_record_ids) { >+ my $deleted_record_id = pop(@deleted_record_ids); >+ return _get_record_for_export( > { > %{$params}, > record_type => 'deleted_bibs', > record_id => $_, >- resultset => $resultset >+ resultset => $deleted_resultset > } > ); >- $record ? $record : (); >- } @{$deleted_record_ids}; >- } >- if ( $format eq 'iso2709' ) { >+ } >+ return; >+ }; >+ >+ if ($format eq 'iso2709') { > my $encoding_validator = sub { >- my ( $record, $record_type ) = @_; >+ my ( $record ) = @_; > my @decoding_warnings = > eval { MARC::File::USMARC->decode( $record->as_usmarc )->warnings() }; > my $error = $@; > if ( $error || @decoding_warnings ) { >+ my $record_status = substr $record->leader(), 5, 1; >+ my $msg = $record_status eq 'd' ? "Deleted record" : "Record"; > my ( $id_tag, $id_code ) = GetMarcFromKohaField( 'biblio.biblionumber', '' ); > my $field = $record->field($id_tag); >- my $msg = "$record_type"; > if ($field) { > $msg .= " " . $field->is_control_field ? $field->data : $field->subfield($id_code); > } >@@ -275,35 +277,31 @@ sub export { > } > return 1; > }; >- for my $record ( grep { $encoding_validator->( $_, 'Record' ) } @records ) { >- print $record->as_usmarc(); >- } >- if (@deleted_records) { >- for my $deleted_record ( grep { $encoding_validator->( $_, 'Deleted record' ) } @deleted_records ) { >- print $deleted_record->as_usmarc(); >+ while (defined ( my $record = $records_iterator->() )) { >+ if ($encoding_validator->($record)) { >+ print $record->as_usmarc(); > } > } >- } elsif ( $format eq 'xml' ) { >+ } elsif ($format eq 'xml') { > my $marcflavour = C4::Context->preference("marcflavour"); > MARC::File::XML->default_record_format( > ( $marcflavour eq 'UNIMARC' && $record_type eq 'auths' ) ? 'UNIMARCAUTH' : $marcflavour ); > print MARC::File::XML::header(); > print "\n"; >- for my $record ( @records, @deleted_records ) { >+ while (defined ( my $record = $records_iterator->() )) { > print MARC::File::XML::record($record); > print "\n"; > } > print MARC::File::XML::footer(); > print "\n"; > } >- } elsif ( $format eq 'csv' ) { >+ } elsif ($format eq 'csv') { > die 'There is no valid csv profile defined for this export' > unless Koha::CsvProfiles->find($csv_profile_id); > print marc2csv( $record_ids, $csv_profile_id, $itemnumbers ); > } > close $fh if $output_filepath; > } >- > 1; > > __END__ >-- >2.48.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 20551
:
73916
|
73923
|
75113
|
82843
|
82914
|
82918
|
90184
|
90190
|
90220
|
93619
|
93620
|
93621
|
105403
|
116408
|
116409
|
116410
|
116411
|
123099
|
123101
|
123102
|
125211
|
125212
|
125213
|
125214
|
125215
|
125216
|
128895
|
128896
|
128897
|
128898
|
128899
|
128900
|
132936
|
132937
|
176623
|
176624
|
176625
|
176626
|
176627
|
176628
|
176629
|
176630
|
176631
|
177536
|
178343
|
178344
|
178345
|
178346
|
178347
|
178348
|
178349
|
178350
|
178351
|
178352
|
178353
|
178378
|
178379
|
178575
|
178617
|
178618
|
178619
|
178679
|
178680
|
178681
|
178682
|
179748
|
179749
|
180648
|
180649
|
180650
|
180651
|
180652
|
180653
|
180654
|
180655
|
180656
|
180657
|
180658
|
180659
|
180660
|
180661
|
180662
|
180663
|
180664
|
180665