Bug 23793 - Add an EmbedItems RecordProcessor filter for MARC::Record objects
Summary: Add an EmbedItems RecordProcessor filter for MARC::Record objects
Status: Pushed to master
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:
  Show dependency treegraph
 
Reported: 2019-10-10 16:10 UTC by Tomás Cohen Arazi
Modified: 2019-10-28 09:11 UTC (History)
9 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Who signed the patch off:
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