From 2499e3241059f9de42abfb536316eedb70f9723d Mon Sep 17 00:00:00 2001 From: dbs Date: Fri, 7 Jan 2011 04:58:05 +0000 Subject: [PATCH] Prevent tag array from growing insanely in supercat browses Modifying the passed-in tag array reference apparently resulted in those changes persisting to the next call, growing the tag array at a rapid clip. So we needed to clean that up. Also, applying the DISTINCT transform to the afr.record column, while a valiant effort, didn't actually work. distinct() is not DISTINCT ON () for starters; also, because DISTINCT ON needs to have the ORDER BY clause match its arguments, and we actually want to order by afr.value, not afr.record. We could do it in a subquery, then reorder by value in the outer SELECT, but it's not clear that json_query supports DISTINCT ON anyway. Some days I wish I could just write SQL. We could retrieve only the afr.record column - it's not clear that any callers actually need the naco-normalized value column - but that seems like a pretty major change at this point. git-svn-id: svn://svn.open-ils.org/ILS/trunk@19132 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/SuperCat.pm | 40 +++++++++------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm index 31e92921bc..9285033226 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm @@ -1006,13 +1006,13 @@ sub authority_tag_sf_browse { my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' ); # .refs variant includes 4xx and 5xx variants for see / see also - if ($self->api_name =~ /\.refs\./) { - my @ref_tags; - foreach my $tagname (@$tag) { + my @ref_tags = (); + foreach my $tagname (@$tag) { + push(@ref_tags, $tagname); + if ($self->api_name =~ /\.refs\./) { push(@ref_tags, '4' . substr($tagname, 1, 2)); push(@ref_tags, '5' . substr($tagname, 1, 2)); } - push(@$tag, @ref_tags); } my @list = (); @@ -1020,12 +1020,10 @@ sub authority_tag_sf_browse { if ($page < 0) { my $before = $_storage->request( "open-ils.cstore.json_query.atomic", - { select => { afr => [ - { transform => "distinct", column => "record" }, - "value" ]}, + { select => { afr => [qw/record value/] }, from => { 'are', 'afr' }, where => { - '+afr' => { tag => $tag, subfield => $subfield, value => { '<' => lc($value) } }, + '+afr' => { tag => \@ref_tags, subfield => $subfield, value => { '<' => lc($value) } }, '+are' => { 'deleted' => 'f' } }, order_by => { afr => { value => 'desc' } }, @@ -1039,12 +1037,10 @@ sub authority_tag_sf_browse { if ($page >= 0) { my $after = $_storage->request( "open-ils.cstore.json_query.atomic", - { select => { afr => [ - { transform => "distinct", column => "record" }, - "value" ]}, + { select => { afr => [qw/record value/] }, from => { 'are', 'afr' }, where => { - '+afr' => { tag => $tag, subfield => $subfield, value => { '>=' => lc($value) } }, + '+afr' => { tag => \@ref_tags, subfield => $subfield, value => { '>=' => lc($value) } }, '+are' => { 'deleted' => 'f' } }, order_by => { afr => { value => 'asc' } }, @@ -1496,14 +1492,14 @@ sub authority_tag_sf_startwith { my $offset = $limit * abs($page); my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' ); + my @ref_tags = (); # .refs variant includes 4xx and 5xx variants for see / see also - if ($self->api_name =~ /\.refs\./) { - my @ref_tags; - foreach my $tagname (@$tag) { + foreach my $tagname (@$tag) { + push(@ref_tags, $tagname); + if ($self->api_name =~ /\.refs\./) { push(@ref_tags, '4' . substr($tagname, 1, 2)); push(@ref_tags, '5' . substr($tagname, 1, 2)); } - push(@$tag, @ref_tags); } my @list = (); @@ -1514,12 +1510,10 @@ sub authority_tag_sf_startwith { my $before = $_storage->request( "open-ils.cstore.json_query.atomic", - { select => { afr => [ - { transform => "distinct", column => "record" }, - "value" ]}, + { select => { afr => [qw/record value/] }, from => { 'afr', 'are' }, where => { - '+afr' => { tag => $tag, subfield => $subfield, value => { '<' => lc($value) } }, + '+afr' => { tag => \@ref_tags, subfield => $subfield, value => { '<' => lc($value) } }, '+are' => { deleted => 'f' } }, order_by => { afr => { value => 'desc' } }, @@ -1533,12 +1527,10 @@ sub authority_tag_sf_startwith { if ($page >= 0) { my $after = $_storage->request( "open-ils.cstore.json_query.atomic", - { select => { afr => [ - { transform => "distinct", column => "record" }, - "value" ]}, + { select => { afr => [qw/record value/] }, from => { 'afr', 'are' }, where => { - '+afr' => { tag => $tag, subfield => $subfield, value => { '>=' => lc($value) } }, + '+afr' => { tag => \@ref_tags, subfield => $subfield, value => { '>=' => lc($value) } }, '+are' => { deleted => 'f' } }, order_by => { afr => { value => 'asc' } }, -- 2.11.0