I think we should introduce a Koha::Filter for replacing AV codes with AV values in the MARC::Record.. we already do this using C4::XSLT::transformMARCXML4XSLT but I believe a RecordProcessor makes more sense than to hide the function away in the defunct XSLT module. We can then use this anywhere we have a RecordProcessor instantiated and get the goodness of filtered MARC::Records.
Created attachment 135338 [details] [review] Bug 30848: Add an AuthorizedValues RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces AV codes with AC descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('AuthorizedValues'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record );
I would call it something like ExpandAuthorizedValues. We just need some tests?
Created attachment 135353 [details] [review] Bug 30848: Add an AuthorizedValues RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces AV codes with AC descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('AuthorizedValues'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record );
Unit tests to come.. it hit end of day here so they'll be a tomorrow job now.. Works beautifully in bug 30744 though ;P
I can rename it tomorrow too :)
Created attachment 135363 [details] [review] Bug 30848: Unit test
Created attachment 135364 [details] [review] Bug 30848: Add an AuthorizedValues RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces AV codes with AC descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandAuthorizedValues'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record );
Created attachment 135386 [details] [review] Bug 30848: Unit test
Created attachment 135387 [details] [review] Bug 30848: Add an AuthorizedValues RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces AV codes with AC descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandAuthorizedValues'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record );
Created attachment 135388 [details] [review] Bug 30848: Caching for performance
The cached version seems to be pretty amazing for performance.. orders of magnitude better than the C4::XSLT routine. However, I've only done the cache populating here.. we'll need to flush this cache appropriately on Library, Itemtype, ClassSource, AV and Framework changes..
Also.. I think we should rename it again from ExpandAuthorizedValues to ExpandKohaCodes.. we're catching more than I first realised here.. it's not just AV's.
Created attachment 135418 [details] [review] Bug 30848: Ensure we flush the cache as necessary
OK.. I need to consider itemtype description translations.. right now my code is ignorant to that.
As mentioned in bug 28371#c2 I'm starting to think I'm caching in the wrong place.. we could cache the individual parts quite easily and flush less with each update that way.. Would looking up 4 smaller caches be significantly less performance than the single larger cache I wonder?
Seeing several: Koha::BiblioFrameworks->search()->get_column('frameworkcode') Any way to get rid of additional DB access in order to flush cache ;) ?
(In reply to Martin Renvoize from comment #15) > As mentioned in bug 28371#c2 I'm starting to think I'm caching in the wrong > place.. we could cache the individual parts quite easily and flush less with > each update that way.. > > Would looking up 4 smaller caches be significantly less performance than the > single larger cache I wonder? We had a comment clash :)
(In reply to Marcel de Rooy from comment #16) > Seeing several: > Koha::BiblioFrameworks->search()->get_column('frameworkcode') > > Any way to get rid of additional DB access in order to flush cache ;) ? Not easily the way it's currently written ;P
Created attachment 135421 [details] [review] Bug 30848: Unit test
Created attachment 135422 [details] [review] Bug 30848: Add an AuthorizedValues RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces AV codes with AC descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandAuthorizedValues'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record );
Created attachment 135423 [details] [review] Bug 30848: Caching for performance
Created attachment 135424 [details] [review] Bug 30848: Ensure we flush the cache as necessary
Created attachment 135425 [details] [review] Bug 30848: Move caching level
Caching moved.. now I need to follow through and fix the 'Ensure we flush the cache' patch to flush appropriately now we have multiple small caches instead of a single larger structure per framework.
Created attachment 135707 [details] [review] Bug 30848: Unit test
Created attachment 135708 [details] [review] Bug 30848: Add an AuthorizedValues RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces AV codes with AC descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandAuthorizedValues'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record );
Created attachment 135709 [details] [review] Bug 30848: Caching for performance
Created attachment 135710 [details] [review] Bug 30848: Ensure we flush the cache as necessary
Created attachment 135711 [details] [review] Bug 30848: Move caching level
Created attachment 135712 [details] [review] Bug 30848: Ensure we flush the cache as necessary
Created attachment 135713 [details] [review] Bug 30848: Rename to ExpandCodedFields
Created attachment 135714 [details] [review] Bug 30848: Unit test
Created attachment 135715 [details] [review] Bug 30848: Add an AuthorizedValues RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces AV codes with AC descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandAuthorizedValues'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record );
Created attachment 135716 [details] [review] Bug 30848: Caching for performance This patch adds caching to ExpandAuthorizedValues for performance. We cache each hash involved in C4::Biblio::GetAuthorisedValueDesc as well as caching the reduced marc subfield structure that filter down to just those marc fields with coded substitutions.
Created attachment 135717 [details] [review] Bug 30848: Rename to ExpandCodedFields
OK, squashed and refined as discussed.. ready for review. This patchset does two things, we introduce a new Koha::Filter::MARC::ExpandCodedValues record processor to allow Marc records to have their Koha coded fields expanded from codes to descriptions/values. (We can use this to replace C4::XSLT::transformMARCXML4XSLT but also add it in wherever we're already calling record processor to get a proper representative record for display). Additionally, we add caching to improve performance.. after working through this a few times to pick the appropriate cache level, I think we've got it now.
Created attachment 135770 [details] [review] Bug 30848: Add an ExpandCodedFields RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces Koha codes with descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandCodedFields'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record ); Test plan * Read the included unit test and confirm it makes sense and passes
Patchset reduced to just the introduction of the ExpandCodedFields filter.. description caching moved to a subsequent bug for self-contained testing etc.
This code is intended to eventually replace C4::XSLT::transformMARCXML4XSLT and the private function C4::XSLT::getAuthorisedValues4MARCSubfields whilst also introducing a more standardised way of achieving code substitutions for Marc records.
I've always liked the RecordProcessor pattern myself. And love what I'm seeing. Is this missing branches, itemtypes, etc?
(In reply to Tomás Cohen Arazi from comment #40) > Is this missing branches, itemtypes, etc? This intended to be: 'Is this missing tests for branches, itemtypes, etc?'
Created attachment 136025 [details] [review] Bug 30848: Add an ExpandCodedFields RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces Koha codes with descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandCodedFields'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record ); Test plan * Read the included unit test and confirm it makes sense and passes
Created attachment 136026 [details] [review] Bug 30848: Expand unit tests Add to the unit tests to test Library and Itemtype expansions as well as linking multiple subfields of the same marc field to such expansions.
Created attachment 136027 [details] [review] Bug 30848: Fix issue exposed by unit tests This patch changes the 'map' to a simple for loop so that we can easily map multiple subfields to a field without overwriting the first previous subfields in the structure.
Created attachment 136259 [details] [review] Bug 30848: Add an ExpandCodedFields RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces Koha codes with descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandCodedFields'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record ); Test plan * Read the included unit test and confirm it makes sense and passes Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Created attachment 136260 [details] [review] Bug 30848: Expand unit tests Add to the unit tests to test Library and Itemtype expansions as well as linking multiple subfields of the same marc field to such expansions. Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Created attachment 136261 [details] [review] Bug 30848: Fix issue exposed by unit tests This patch changes the 'map' to a simple for loop so that we can easily map multiple subfields to a field without overwriting the first previous subfields in the structure. Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Created attachment 136262 [details] [review] Bug 30848: Add exec flag to test Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Created attachment 136774 [details] [review] Bug 30848: Add an ExpandCodedFields RecordProcessor filter This patch introduces a RecordProcessor filter for MARC::Record objects that replaces Koha codes with descriptions in the MARC::Record passed to the processor. Target usage: my $biblio = Koha::Biblios->find( $biblio_id, { prefetch => [ metadata ] } ); my $record = $biblio->metadata->record; my $processor = Koha::RecordProcessor->new( { filters => ('ExpandCodedFields'), options => { interface => 'opac', frameworkcode => $biblio->frameworkcode } } ); $processor->process( $record ); Test plan * Read the included unit test and confirm it makes sense and passes Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 136775 [details] [review] Bug 30848: Expand unit tests Add to the unit tests to test Library and Itemtype expansions as well as linking multiple subfields of the same marc field to such expansions. Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 136776 [details] [review] Bug 30848: Fix issue exposed by unit tests This patch changes the 'map' to a simple for loop so that we can easily map multiple subfields to a field without overwriting the first previous subfields in the structure. Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Created attachment 136777 [details] [review] Bug 30848: Add exec flag to test Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Pushed to master for 22.11. Nice work everyone, thanks!
Backported to 22.05.x for 22.05.04
pushed to 21.11.x for 21.11.11
Not backported to oldoldstable (21.05.x). Feel free to ask if it's needed. Nothing to document, marking resolved.
Will backport because it's a dependency of 30744
There is a remaining diag() in the tests, shall it stay here?
For 21.05.x In C4::Biblio I have to export GetMarcSubfieldStructure (like in other branches) so the tests compile. No problem to do that, right?
Backported: Pushed to 21.05.x branch for 21.05.18