Bug 23793 - Add an EmbedItems RecordProcessor filter for MARC::Record objects
Summary: Add an EmbedItems RecordProcessor filter for MARC::Record objects
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Testopia
URL:
Keywords:
Depends on: 23807
Blocks: 29764
  Show dependency treegraph
 
Reported: 2019-10-10 16:10 UTC by Tomás Cohen Arazi
Modified: 2021-12-23 12:03 UTC (History)
9 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
19.11.00


Attachments
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects (3.49 KB, patch)
2019-10-10 16:20 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects (3.49 KB, patch)
2019-10-10 16:38 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects (3.22 KB, patch)
2019-10-11 17:45 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects (3.55 KB, patch)
2019-10-14 12:12 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 23793: Unit tests (2.93 KB, patch)
2019-10-14 12:12 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects (3.60 KB, patch)
2019-10-23 06:53 UTC, Ere Maijala
Details | Diff | Splinter Review
Bug 23793: Unit tests (2.98 KB, patch)
2019-10-23 06:53 UTC, Ere Maijala
Details | Diff | Splinter Review
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects (3.67 KB, patch)
2019-10-23 10:46 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 23793: Unit tests (3.05 KB, patch)
2019-10-23 10:47 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2019-10-10 16:10:25 UTC
This should help reduce the current overhead, and by using the features introduced by bug 22454, probably give a performance boost.
Comment 1 Tomás Cohen Arazi 2019-10-10 16:20:17 UTC Comment hidden (obsolete)
Comment 2 Tomás Cohen Arazi 2019-10-10 16:21:07 UTC Comment hidden (obsolete)
Comment 3 Tomás Cohen Arazi 2019-10-10 16:38:43 UTC Comment hidden (obsolete)
Comment 4 Tomás Cohen Arazi 2019-10-11 17:45:36 UTC Comment hidden (obsolete)
Comment 5 Tomás Cohen Arazi 2019-10-11 17:46:45 UTC Comment hidden (obsolete)
Comment 6 Tomás Cohen Arazi 2019-10-14 12:12:18 UTC
Created attachment 94095 [details] [review]
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects

This patch introduces a RecordProcessor filter for MARC::Record objects
that embeds MARC::Field's for each item that is passed to the processor.

Target usage:

my $biblio = Koha::Biblios->find(
    $biblio_id,
    { prefetch => [ items, metadata ] }
);

my $opachiddenitems_rules;
eval {
    my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n";
    $opachiddenitems_rules = YAML::Load($yaml);
};

my @items  = grep { !$_->hidden_in_opac({ rules => $opachiddenitems_rules }) @{$biblio->items->as_list};
my $record = $biblio->metadata->record;

my $processor = Koha::RecordProcessor->new(
    {
        filters => ('EmbedItems'),
        options => {
            items        => \@items
        }
    }
);

$processor->process( $record );
Comment 7 Tomás Cohen Arazi 2019-10-14 12:12:23 UTC
Created attachment 94096 [details] [review]
Bug 23793: Unit tests

This patch introduces full test coverage for the EmbedItems filter.

To test:
1. Apply this patchset
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Filter/EmbedItems.t
=> SUCCESS: Tests pass!
3. Sign off :-D
4. Use it to improve Koha!
Comment 8 Ere Maijala 2019-10-22 12:49:43 UTC
This looks great, but wouldn't it be nice to put it into use right away?
Comment 9 Tomás Cohen Arazi 2019-10-22 12:50:27 UTC
(In reply to Ere Maijala from comment #8)
> This looks great, but wouldn't it be nice to put it into use right away?

Yes, but I wanted your opinion first!
Comment 10 Ere Maijala 2019-10-22 12:52:08 UTC
+1 for this, I'm going to close my old optimization bug. :)
Comment 11 Katrin Fischer 2019-10-23 05:51:04 UTC
(In reply to Ere Maijala from comment #10)
> +1 for this, I'm going to close my old optimization bug. :)

Can we talk you into a sign-off? :)
Comment 12 Ere Maijala 2019-10-23 06:53:15 UTC
Created attachment 94599 [details] [review]
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects

This patch introduces a RecordProcessor filter for MARC::Record objects
that embeds MARC::Field's for each item that is passed to the processor.

Target usage:

my $biblio = Koha::Biblios->find(
    $biblio_id,
    { prefetch => [ items, metadata ] }
);

my $opachiddenitems_rules;
eval {
    my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n";
    $opachiddenitems_rules = YAML::Load($yaml);
};

my @items  = grep { !$_->hidden_in_opac({ rules => $opachiddenitems_rules }) @{$biblio->items->as_list};
my $record = $biblio->metadata->record;

my $processor = Koha::RecordProcessor->new(
    {
        filters => ('EmbedItems'),
        options => {
            items        => \@items
        }
    }
);

$processor->process( $record );

Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Comment 13 Ere Maijala 2019-10-23 06:53:18 UTC
Created attachment 94600 [details] [review]
Bug 23793: Unit tests

This patch introduces full test coverage for the EmbedItems filter.

To test:
1. Apply this patchset
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Filter/EmbedItems.t
=> SUCCESS: Tests pass!
3. Sign off :-D
4. Use it to improve Koha!

Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Comment 14 Ere Maijala 2019-10-23 06:54:39 UTC
Ok, fine. :) I trust that there will be something using this soon. I'm generally not in favour of adding functionality without anything using it since there's always a risk that something happens and it ends up never being used.
Comment 15 Martin Renvoize 2019-10-23 10:46:59 UTC
Created attachment 94602 [details] [review]
Bug 23793: Add an EmbedItems RecordProcessor filter for MARC::Record objects

This patch introduces a RecordProcessor filter for MARC::Record objects
that embeds MARC::Field's for each item that is passed to the processor.

Target usage:

my $biblio = Koha::Biblios->find(
    $biblio_id,
    { prefetch => [ items, metadata ] }
);

my $opachiddenitems_rules;
eval {
    my $yaml = C4::Context->preference('OpacHiddenItems') . "\n\n";
    $opachiddenitems_rules = YAML::Load($yaml);
};

my @items  = grep { !$_->hidden_in_opac({ rules => $opachiddenitems_rules }) @{$biblio->items->as_list};
my $record = $biblio->metadata->record;

my $processor = Koha::RecordProcessor->new(
    {
        filters => ('EmbedItems'),
        options => {
            items        => \@items
        }
    }
);

$processor->process( $record );

Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 16 Martin Renvoize 2019-10-23 10:47:03 UTC
Created attachment 94603 [details] [review]
Bug 23793: Unit tests

This patch introduces full test coverage for the EmbedItems filter.

To test:
1. Apply this patchset
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Filter/EmbedItems.t
=> SUCCESS: Tests pass!
3. Sign off :-D
4. Use it to improve Koha!

Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 17 Martin Renvoize 2019-10-23 10:48:07 UTC
Passes QA scripts, Passes tests.. Passing QA.

I trust Tomas to followup with uses of this in new bugs soon :)
Comment 18 Martin Renvoize 2019-10-23 16:33:33 UTC
Nice work!

Pushed to master for 19.11.00
Comment 19 David Cook 2021-12-10 04:38:55 UTC
(In reply to Ere Maijala from comment #14)
> Ok, fine. :) I trust that there will be something using this soon. I'm
> generally not in favour of adding functionality without anything using it
> since there's always a risk that something happens and it ends up never
> being used.

I don't think there's any core functionality that is using it today unfortunately.
Comment 20 Tomás Cohen Arazi 2021-12-10 11:02:41 UTC
(In reply to David Cook from comment #19)
> (In reply to Ere Maijala from comment #14)
> > Ok, fine. :) I trust that there will be something using this soon. I'm
> > generally not in favour of adding functionality without anything using it
> > since there's always a risk that something happens and it ends up never
> > being used.
> 
> I don't think there's any core functionality that is using it today
> unfortunately.

opac/opac-ISBDdetail.pl
Comment 21 David Cook 2021-12-22 22:56:37 UTC
(In reply to Tomás Cohen Arazi from comment #20)
> 
> opac/opac-ISBDdetail.pl

Cool. I'm going to use it in some local code now. The sample code in the documentation doesn't work but working out the right way of doing it...
Comment 22 Tomás Cohen Arazi 2021-12-23 12:03:56 UTC
(In reply to David Cook from comment #21)
> (In reply to Tomás Cohen Arazi from comment #20)
> > 
> > opac/opac-ISBDdetail.pl
> 
> Cool. I'm going to use it in some local code now. The sample code in the
> documentation doesn't work but working out the right way of doing it...

I fixed the POD on bug 29764. Please test. The only change is parenthesis for square brackets in the filters list.