From 06a2f7a77d2238a7e28309461fb24342f30ede28 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Thu, 27 Oct 2011 13:38:50 -0400 Subject: [PATCH] faster streaming, attempt 1 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 --- Open-ILS/src/c-apps/oils_sql.c | 141 +++++++++++++++++++++++++---------------- 1 file changed, 86 insertions(+), 55 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_sql.c b/Open-ILS/src/c-apps/oils_sql.c index e1869e9eb7..40842a4d37 100644 --- a/Open-ILS/src/c-apps/oils_sql.c +++ b/Open-ILS/src/c-apps/oils_sql.c @@ -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; + } } -- 2.11.0