From df424b2b4f10116b31b85bdd7c6c02243d4a2926 Mon Sep 17 00:00:00 2001 From: dbwells Date: Fri, 1 Apr 2011 15:17:51 +0000 Subject: [PATCH] Better search normalization de-duping when 'params' are used This patch addresses search normalization deduping at two levels. We now verify that both the function and the params are the same before excluding a normalization, both when the normalization is first added to the set and when the SQL is being built (since currently multiple sets may be involved). git-svn-id: svn://svn.open-ils.org/ILS/trunk@19924 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/Driver/Pg/QueryParser.pm | 5 +++-- .../lib/OpenILS/Application/Storage/QueryParser.pm | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index c74ffeeacc..f207eb08cc 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -802,8 +802,9 @@ sub buildSQL { for my $nfield (keys %$normalizers) { for my $nizer ( @{$$normalizers{$nfield}} ) { if ($field eq $nfield) { - if (!exists($norms{$nizer->{function}})) { - $norms{$nizer->{function}} = {p=>$pos++,n=>$nizer}; + my $param_string = OpenSRF::Utils::JSON->perl2JSON($nizer->{params}); + if (!exists($norms{$nizer->{function}.$param_string})) { + $norms{$nizer->{function}.$param_string} = {p=>$pos++,n=>$nizer}; } } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/QueryParser.pm index 7792b49ace..1bee5623d3 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/QueryParser.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/QueryParser.pm @@ -1,4 +1,5 @@ package QueryParser; +use OpenSRF::Utils::JSON; our %parser_config = ( QueryParser => { filters => [], @@ -180,7 +181,11 @@ sub add_query_normalizer { my $func = shift; my $params = shift || []; - return $func if (grep { $_ eq $func } @{$pkg->query_normalizers->{$class}->{$field}}); + # do not add if function AND params are identical to existing member + return $func if (grep { + $_->{function} eq $func and + OpenSRF::Utils::JSON->perl2JSON($_->{params}) eq OpenSRF::Utils::JSON->perl2JSON($params) + } @{$pkg->query_normalizers->{$class}->{$field}}); push(@{$pkg->query_normalizers->{$class}->{$field}}, { function => $func, params => $params }); -- 2.43.2