Bugzilla – Attachment 156273 Details for
Bug 31383
Additional contents: We need a parent and child table
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31383: Use one query in search_for_display instead of four
Bug-31383-Use-one-query-in-searchfordisplay-instea.patch (text/plain), 3.69 KB, created by
Martin Renvoize (ashimema)
on 2023-09-27 10:01:47 UTC
(
hide
)
Description:
Bug 31383: Use one query in search_for_display instead of four
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-09-27 10:01:47 UTC
Size:
3.69 KB
patch
obsolete
>From 2c04083ad0de82660eb8afded929e91d652ea0ef Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 21 Jun 2023 12:38:54 +0000 >Subject: [PATCH] Bug 31383: Use one query in search_for_display instead of > four > >Benchmarking does however not show real performance gain. >But it might be considered as a code improvement? > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/AdditionalContents.pm | 53 ++++++++++++-------------------------- > 1 file changed, 17 insertions(+), 36 deletions(-) > >diff --git a/Koha/AdditionalContents.pm b/Koha/AdditionalContents.pm >index 4b97fc1d837..bbad4869a2a 100644 >--- a/Koha/AdditionalContents.pm >+++ b/Koha/AdditionalContents.pm >@@ -73,44 +73,25 @@ location is one of this: > > sub search_for_display { > my ( $self, $params ) = @_; >+ my $lang = $params->{lang}; > >- my $search_params; >- $search_params->{location} = $params->{location}; >- $search_params->{branchcode} = $params->{library_id} ? [ $params->{library_id}, undef ] : undef; >- $search_params->{published_on} = { '<=' => \'CAST(NOW() AS DATE)' }; >- $search_params->{-or} = [ >- expirationdate => { '>=' => \'CAST(NOW() AS DATE)' }, >- expirationdate => undef >- ]; >- $search_params->{category} = $params->{category} if $params->{category}; >- >- my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } ); >- my @all_content_id = $contents->get_column('id'); >- >- my ( $translated_contents, @translated_content_id ); >- if ( $params->{lang} && $params->{lang} ne 'default' ) { >- $translated_contents = Koha::AdditionalContentsLocalizations->search( >- { >- additional_content_id => [$contents->get_column('id')], >- lang => $params->{lang}, >- } >- ); >- @translated_content_id = $translated_contents->get_column('additional_content_id'); >- } >- >- my $default_contents = Koha::AdditionalContentsLocalizations->search( >- { >- additional_content_id => [array_minus(@all_content_id, @translated_content_id)], >- lang => 'default', >- } >- ); >- >- return Koha::AdditionalContentsLocalizations->search( >- { >- id => [ $translated_contents ? $translated_contents->get_column('id') : (), $default_contents->get_column('id') ] >- }, >- ); >+ # If lang is not default, we will search for entries matching $lang but fallback to default if $lang is not found >+ # Then we need a subquery count in where clause; DBIx::Class/SQL::Abstract does not support it, fallback to literal SQL >+ my $subquery = >+ qq|(SELECT COUNT(*) FROM additional_contents_localizations WHERE lang='$lang' AND additional_content_id=me.additional_content_id)=0|; > >+ my $search_params; >+ $search_params->{location} = $params->{location}; >+ $search_params->{branchcode} = $params->{library_id} ? [ $params->{library_id}, undef ] : undef; >+ $search_params->{published_on} = { '<=' => \'CAST(NOW() AS DATE)' }; >+ $search_params->{expirationdate} = [ '-or', { '>=' => \'CAST(NOW() AS DATE)' }, undef ]; >+ $search_params->{category} = $params->{category} if $params->{category}; >+ $search_params->{lang} = 'default' if !$lang || $lang eq 'default'; >+ $search_params->{-or} = [ { 'lang' => $lang }, '-and' => [ 'lang', 'default', \$subquery ] ] >+ if !$search_params->{lang}; >+ >+ my $attribs = { prefetch => 'additional_content', order_by => 'additional_content.number' }; >+ return Koha::AdditionalContentsLocalizations->search( $search_params, $attribs ); > } > > =head3 find_best_match >-- >2.41.0
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 31383
:
147891
|
147892
|
147893
|
147894
|
147895
|
147896
|
149813
|
149814
|
149815
|
149816
|
149817
|
149818
|
152423
|
152424
|
152425
|
152426
|
152427
|
152428
|
152545
|
152546
|
152547
|
152566
|
152660
|
152661
|
152662
|
152663
|
152664
|
152665
|
152666
|
152667
|
152668
|
152669
|
153013
|
153666
|
153667
|
153668
|
153669
|
153670
|
153671
|
153672
|
153673
|
153674
|
153675
|
153676
|
156048
|
156049
|
156050
|
156051
|
156052
|
156053
|
156054
|
156055
|
156056
|
156057
|
156058
|
156265
|
156266
|
156267
|
156268
|
156269
|
156270
|
156271
|
156272
|
156273
|
156274
|
156275
|
156276
|
157539
|
157540
|
157541
|
157542
|
157543
|
157544
|
157545
|
157546
|
157547
|
157548
|
157549
|
157550
|
157580
|
157585
|
157640
|
157741
|
157742