faster streaming, attempt 1 pcrud-fleshing-experimental
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 27 Oct 2011 17:38:50 +0000 (13:38 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 28 Feb 2012 16:40:10 +0000 (11:40 -0500)
everything seems to work okay except this gets produced on every request now?

open-ils.pcrud 2011-10-27 15:25:29 [ERR
:5352:oils_sql.c:724:131974311053765] Unexpected object type receieved
from open-ils.auth.session.reset_timeout

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/c-apps/oils_sql.c

index e1869e9..40842a4 100644 (file)
@@ -1201,14 +1201,17 @@ int doSearch( osrfMethodContext* ctx ) {
                return -1;
        }
 
-       // Return each row to the client
-       jsonObject* cur = 0;
-       unsigned long res_idx = 0;
-       while((cur = jsonObjectGetIndex( obj, res_idx++ ) )) {
-               // We used to discard based on perms here, but now that's
-               // inside doFieldmapperSearch()
-               osrfAppRespond( ctx, cur );
-       }
+       // doFieldmapperSearch() now takes care of our responding for us
+//     // Return each row to the client
+//     jsonObject* cur = 0;
+//     unsigned long res_idx = 0;
+//
+//     while((cur = jsonObjectGetIndex( obj, res_idx++ ) )) {
+//             // We used to discard based on perms here, but now that's
+//             // inside doFieldmapperSearch()
+//             osrfAppRespond( ctx, cur );
+//     }
+
        jsonObjectFree( obj );
 
        osrfAppRespondComplete( ctx, NULL );
@@ -2393,7 +2396,10 @@ int doRetrieve( osrfMethodContext* ctx ) {
                }
        }
 
-       osrfAppRespondComplete( ctx, obj );
+       // doFieldmapperSearch() now does the responding for us
+       //osrfAppRespondComplete( ctx, obj );
+       osrfAppRespondComplete( ctx, NULL );
+
        jsonObjectFree( obj );
        return 0;
 }
@@ -5553,13 +5559,11 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
        if (!ctx->session->userData)
                initSessionCache( ctx );
 
+       char *methodtype = osrfHashGet( (osrfHash *) ctx->method->userData, "methodtype" );
        char *inside_verify = osrfHashGet( (osrfHash*) ctx->session->userData, "inside_verify" );
-       int need_to_verify = 1;
+       int need_to_verify = (inside_verify ? !atoi(inside_verify) : 1);
 
-       if (inside_verify)
-               need_to_verify = !atoi(inside_verify);
-
-       int want_flesh = 0;     // we don't know yet
+       int i_respond_directly = 0;
        int flesh_depth = 0;
 
        // XXX This can be redundant with another instance of the same test that happens
@@ -5615,7 +5619,6 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
        // 1. get the flesh depth
        const jsonObject* _tmp = jsonObjectGetKeyConst( query_hash, "flesh" );
        if( _tmp ) {
-               want_flesh = 1;
                flesh_depth = (int) jsonObjectGetNumber( _tmp );
                if( flesh_depth == -1 || flesh_depth > max_flesh_depth )
                        flesh_depth = max_flesh_depth;
@@ -5624,8 +5627,12 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
        // 2. figure out one consistent rs_size for verifyObjectPCRUD to use
        // over the whole life of this request.  This means if we've already set
        // up a rs_size_req_%d, do nothing.
+       //      a. Incidentally, we can also use this opportunity to set i_respond_directly
        int *rs_size = osrfHashGetFmt( (osrfHash *) ctx->session->userData, "rs_size_req_%d", ctx->request );
-       if (!rs_size) { // pointer null, so value not set in hash
+       if( !rs_size ) {        // pointer null, so value not set in hash
+               // i_respond_directly can only be true at the /top/ of a recursive search, if even that.
+               i_respond_directly = ( *methodtype == 'r' || *methodtype == 'i' || *methodtype == 's' );
+
                rs_size = (int *) safe_malloc( sizeof(int) );   // will be freed by sessionDataFree()
                unsigned long long result_count = dbi_result_get_numrows( result );
                *rs_size = (int) result_count * (flesh_depth + 1);      // yes, we could lose some bits, but come on
@@ -5667,48 +5674,58 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
        // If we're asked to flesh, and there's anything to flesh, then flesh it
        // (formerly we would skip fleshing if in pcrud mode, but now we support
        // fleshing even in PCRUD).
-       if( res_list->size && query_hash && want_flesh ) {
-               // We need a non-zero flesh depth, and a list of fields to flesh
-               const jsonObject* temp_blob = jsonObjectGetKeyConst( query_hash, "flesh_fields" );
-               if( temp_blob && flesh_depth > 0 ) {
-
-                       jsonObject* flesh_blob = jsonObjectClone( temp_blob );
-                       const jsonObject* flesh_fields = jsonObjectGetKeyConst( flesh_blob, core_class );
-
-                       osrfStringArray* link_fields = NULL;
-                       osrfHash* links = osrfHashGet( class_meta, "links" );
-
-                       // Make an osrfStringArray of the names of fields to be fleshed
-                       if( flesh_fields ) {
-                               if( flesh_fields->size == 1 ) {
-                                       const char* _t = jsonObjectGetString(
-                                               jsonObjectGetIndex( flesh_fields, 0 ) );
-                                       if( !strcmp( _t, "*" ))
-                                               link_fields = osrfHashKeys( links );
-                               }
+       if( res_list->size ) {
+               jsonObject* temp_blob;  // We need a non-zero flesh depth, and a list of fields to flesh
+               jsonObject* flesh_fields; 
+               jsonObject* flesh_blob = NULL;
+               osrfStringArray* link_fields = NULL;
+               osrfHash* links = NULL;
+               int want_flesh = 0;
+
+               if( query_hash ) {
+                       temp_blob = jsonObjectGetKey( query_hash, "flesh_fields" );
+                       if( temp_blob && flesh_depth > 0 ) {
+
+                               flesh_blob = jsonObjectClone( temp_blob );
+                               flesh_fields = jsonObjectGetKey( flesh_blob, core_class );
+
+                               links = osrfHashGet( class_meta, "links" );
+
+                               // Make an osrfStringArray of the names of fields to be fleshed
+                               if( flesh_fields ) {
+                                       if( flesh_fields->size == 1 ) {
+                                               const char* _t = jsonObjectGetString(
+                                                       jsonObjectGetIndex( flesh_fields, 0 ) );
+                                               if( !strcmp( _t, "*" ))
+                                                       link_fields = osrfHashKeys( links );
+                                       }
 
-                               if( !link_fields ) {
-                                       jsonObject* _f;
-                                       link_fields = osrfNewStringArray( 1 );
-                                       jsonIterator* _i = jsonNewIterator( flesh_fields );
-                                       while ((_f = jsonIteratorNext( _i ))) {
-                                               osrfStringArrayAdd( link_fields, jsonObjectGetString( _f ) );
+                                       if( !link_fields ) {
+                                               jsonObject* _f;
+                                               link_fields = osrfNewStringArray( 1 );
+                                               jsonIterator* _i = jsonNewIterator( flesh_fields );
+                                               while ((_f = jsonIteratorNext( _i ))) {
+                                                       osrfStringArrayAdd( link_fields, jsonObjectGetString( _f ) );
+                                               }
+                                               jsonIteratorFree( _i );
                                        }
-                                       jsonIteratorFree( _i );
                                }
+                               want_flesh = link_fields ? 1 : 0;
                        }
+               }
 
-                       osrfHash* fields = osrfHashGet( class_meta, "fields" );
+               osrfHash* fields = osrfHashGet( class_meta, "fields" );
 
-                       // Iterate over the JSON_ARRAY of rows
-                       jsonObject* cur;
-                       unsigned long res_idx = 0;
-                       while((cur = jsonObjectGetIndex( res_list, res_idx++ ) )) {
+               // Iterate over the JSON_ARRAY of rows
+               jsonObject* cur;
+               unsigned long res_idx = 0;
+               while((cur = jsonObjectGetIndex( res_list, res_idx++ ) )) {
 
-                               int i = 0;
-                               const char* link_field;
+                       int i = 0;
+                       const char* link_field;
 
-                               // Iterate over the list of fleshable fields
+                       // Iterate over the list of fleshable fields
+                       if ( want_flesh ) {
                                while( (link_field = osrfStringArrayGetString(link_fields, i++)) ) {
 
                                        osrfLogDebug( OSRF_LOG_MARK, "Starting to flesh %s", link_field );
@@ -5893,13 +5910,27 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
                                        osrfLogDebug( OSRF_LOG_MARK, "%s", jsonObjectToJSON( cur ));
 
                                } // end while loop traversing list of fleshable fields
-                       } // end while loop traversing res_list
-                       jsonObjectFree( flesh_blob );
-                       osrfStringArrayFree( link_fields );
-               }
+                       }
+
+                       if( i_respond_directly ) {
+                               if ( *methodtype == 'i' ) {
+                                       osrfAppRespond( ctx,
+                                               oilsFMGetObject( cur, osrfHashGet( class_meta, "primarykey" ) ) );
+                               } else {
+                                       osrfAppRespond( ctx, cur );
+                               }
+                       }
+               } // end while loop traversing res_list
+               jsonObjectFree( flesh_blob );
+               osrfStringArrayFree( link_fields );
        }
 
-       return res_list;
+       if( i_respond_directly ) {
+               jsonObjectFree( res_list );
+               return jsonNewObjectType( JSON_ARRAY );
+       } else {
+               return res_list;
+       }
 }