From e953ba1b9a3260d352f62ca7fa44fd45188e0308 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 10 Apr 2014 13:03:30 -0400 Subject: [PATCH] LP#1306133: Avoid metabib.rec_descriptor where possible metabib.rec_descriptor has been a view over other data structures for some time now, but with the advent of the new attribute infrastructure it is a view over a view over a view, variously transforming IDs to a slim table to an HSTORE structure and finally to a wide table. Thus, it is extremely expensive to query. So we won't unless we're asked to. Which, in the TPAC world, is never. Signed-off-by: Mike Rylander Signed-off-by: Doug Kyle --- .../Application/Storage/Publisher/metabib.pm | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm index 6f29126a6c..625f5ab217 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm @@ -556,12 +556,14 @@ sub biblio_multi_search_full_rec { my ($t_filter, $f_filter) = ('',''); my ($a_filter, $l_filter, $lf_filter) = ('','',''); + my $use_rd = 0; if (my $a = $args{audience}) { $a = [$a] if (!ref($a)); my @aud = @$a; $a_filter = ' AND rd.audience IN ('.join(',',map{'?'}@aud).')'; push @binds, @aud; + $use_rd = 1; } if (my $l = $args{language}) { @@ -570,6 +572,7 @@ sub biblio_multi_search_full_rec { $l_filter = ' AND rd.item_lang IN ('.join(',',map{'?'}@lang).')'; push @binds, @lang; + $use_rd = 1; } if (my $f = $args{lit_form}) { @@ -578,6 +581,7 @@ sub biblio_multi_search_full_rec { $lf_filter = ' AND rd.lit_form IN ('.join(',',map{'?'}@lit_form).')'; push @binds, @lit_form; + $use_rd = 1; } if (my $f = $args{item_form}) { @@ -586,6 +590,7 @@ sub biblio_multi_search_full_rec { $f_filter = ' AND rd.item_form IN ('.join(',',map{'?'}@forms).')'; push @binds, @forms; + $use_rd = 1; } if (my $t = $args{item_type}) { @@ -594,6 +599,7 @@ sub biblio_multi_search_full_rec { $t_filter = ' AND rd.item_type IN ('.join(',',map{'?'}@types).')'; push @binds, @types; + $use_rd = 1; } @@ -603,10 +609,12 @@ sub biblio_multi_search_full_rec { my @forms = split '', $f; if (@types) { $t_filter = ' AND rd.item_type IN ('.join(',',map{'?'}@types).')'; + $use_rd = 1; } if (@forms) { $f_filter .= ' AND rd.item_form IN ('.join(',',map{'?'}@forms).')'; + $use_rd = 1; } push @binds, @types, @forms; } @@ -661,6 +669,8 @@ sub biblio_multi_search_full_rec { $sort = undef; } + my $rd_join = $use_rd ? "$metabib_record_descriptor rd," : ''; + my $rd_filter = $use_rd ? 'AND rd.record = f.record' : ''; if ($copies_visible) { $select = <<" SQL"; @@ -671,16 +681,16 @@ sub biblio_multi_search_full_rec { $cs_table cs, $cl_table cl, $br_table br, - $metabib_record_descriptor rd, + $rd_join $descendants d WHERE br.id = f.record AND cn.record = f.record - AND rd.record = f.record AND cp.status = cs.id AND cp.location = cl.id AND br.deleted IS FALSE AND cn.deleted IS FALSE AND cp.deleted IS FALSE + $rd_filter $has_vols $has_copies $copies_visible @@ -696,11 +706,11 @@ sub biblio_multi_search_full_rec { $select = <<" SQL"; SELECT f.record, 1, 1, $rank FROM $search_table f, - $br_table br, - $metabib_record_descriptor rd + $rd_join + $br_table br WHERE br.id = f.record - AND rd.record = f.record AND br.deleted IS FALSE + $rd_filter $t_filter $f_filter $a_filter -- 2.43.2