From 71863a04e14f6eec656f3e501fc5c35ed02cd0d6 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 22 Mar 2012 09:58:43 -0400 Subject: [PATCH] Provide a prepare/execute API for flattened searches; squash a re-my warning Signed-off-by: Mike Rylander --- .../perlmods/lib/OpenILS/Application/Fielder.pm | 76 +++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm index 9659004de5..4342479755 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm @@ -155,6 +155,79 @@ sub generate_methods { }; } +sub register_map { + my ($self, $conn, $auth, $hint, $map) = @_; + + $key = 'flat_search_' . md5_hex( + $hint . + OpenSRF::Utils::JSON->perl2JSON( $map ) + ); + + $cache->put_cache( $key => { hint => $hint, map => $map } => $cache_timeout ); +} + +__PACKAGE__->register_method( + method => 'register_map', + api_name => 'open-ils.fielder.flattened_search.prepare', + argc => 2, + signature => { + params => [ + {name => "auth", type => "string", desc => "auth token"}, + {name => "hint", type => "string", + desc => "fieldmapper class hint of core object"}, + {name => "map", type => "object", desc => q{ + path-field mapping structure. See documentation under + docs/TechRef/Flattener in the Evergreen source tree.} } + ], + return => { + desc => q{ + A key used to reference a prepared flattened search on subsequent + calls to open-ils.fielder.flattened_search.execute}, + type => "string" + } + } +); + +sub execute_registered_flattened_search { + my $self = shift; + my $conn = shift; + my $auth = shift; + my $key = shift; + + my $blob = $cache->get_cache( $key ); + + flattened_search( $self, $conn, $auth, $blob->{hint}, $blob->{map}, @_ ) + if (ref($blob) and $blob->{hint} and $blob->{map}); +} + +__PACKAGE__->register_method( + method => 'execute_registered_flattened_search', + api_name => 'open-ils.fielder.flattened_search.execute', + stream => 1, + argc => 5, + signature => { + params => [ + {name => "auth", type => "string", desc => "auth token"}, + {name => "key", type => "string", + desc => "Key for a registered map provided by open-ils.fielder.flattened_search.prepare"}, + {name => "where", type => "object", desc => q{ + simplified query clause (like the 'where' clause of a + json_query, but different). See documentation under + docs/TechRef/Flattener in the Evergreen source tree.} }, + {name => "slo", type => "object", desc => q{ + simplified sort/limit/offset object. See documentation under + docs/TechRef/Flattener in the Evergreen source tree.} } + ], + return => { + desc => q{ + A stream of objects flattened to your specifications. See + documentation under docs/TechRef/Flattener in the Evergreen + source tree.}, + type => "object" + } + } +); + sub flattened_search { my ($self, $conn, $auth, $hint, $map, $where, $slo) = @_; @@ -163,7 +236,8 @@ sub flattened_search { # Process the map to normalize it, and to get all our joins and fleshing # structure into the jffolo. - my ($map, $jffolo) = + my $jffolo; + ($map, $jffolo) = OpenILS::Application::Flattener::process_map($hint, $map); # Process the suppied where clause, using our map, to make the -- 2.11.0