Provide a prepare/execute API for flattened searches; squash a re-my warning flattener-on-master
authorMike Rylander <mrylander@gmail.com>
Thu, 22 Mar 2012 13:58:43 +0000 (09:58 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 22 Mar 2012 13:58:43 +0000 (09:58 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Fielder.pm

index 9659004..4342479 100644 (file)
@@ -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