From 9e7549aa1ea71ee55f489beb9962cd3ef27dfa71 Mon Sep 17 00:00:00 2001 From: phasefx Date: Thu, 5 Jul 2007 21:16:30 +0000 Subject: [PATCH] I'm ripping the experimental network caching out of trunk; I want to start over in an separate branch git-svn-id: svn://svn.open-ils.org/ILS/trunk@7525 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../staff_client/chrome/content/OpenILS/data.js | 8 -- .../staff_client/chrome/content/main/constants.js | 2 +- .../staff_client/chrome/content/util/network.js | 98 ++++------------------ Open-ILS/xul/staff_client/server/circ/checkout.js | 2 +- Open-ILS/xul/staff_client/server/main/data.xul | 18 +--- Open-ILS/xul/staff_client/server/patron/display.js | 1 - .../xul/staff_client/server/patron/info_notes.xul | 2 +- Open-ILS/xul/staff_client/server/patron/summary.js | 4 +- Open-ILS/xul/staff_client/server/patron/util.js | 14 ++-- 9 files changed, 27 insertions(+), 122 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js b/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js index a9ebff46a6..f4ece92d53 100644 --- a/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js +++ b/Open-ILS/xul/staff_client/chrome/content/OpenILS/data.js @@ -14,7 +14,6 @@ OpenILS.data.prototype = { 'list' : {}, 'hash' : {}, 'tree' : {}, - 'cached_request' : {}, 'temp' : '', @@ -448,13 +447,6 @@ OpenILS.data.prototype = { obj.error.sdump_levels.D_SES_RESULT = level; convert(); obj.data_progress('Retrieved list for ' + classname + ' objects. '); - // if cacheable, store an offline copy - /* FIXME -- we're going to revisit caching and do it differently - if (cacheable) { - var file = new util.file( classname ); - file.set_object( obj.list[classname] ); - } - */ } catch(E) { // if cacheable, try offline diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index 5447875268..2ee34b1575 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -70,7 +70,7 @@ const api = { 'FM_AHR_ID_LIST_PULL_LIST' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.hold_pull_list.id_list.retrieve', 'secure' : false }, 'FM_AHR_ONSHELF_RETRIEVE' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.captured_holds.on_shelf.retrieve' }, 'FM_AHR_ID_LIST_ONSHELF_RETRIEVE' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.captured_holds.id_list.on_shelf.retrieve', 'secure' : false }, - 'FM_AHR_COUNT_RETRIEVE' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.hold_requests.count' }, + 'FM_AHR_COUNT_RETRIEVE' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.hold_requests.count', 'cacheable' : true, 'ttl' : 60000 }, 'FM_AHR_CANCEL' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.hold.cancel' }, 'FM_AHR_UPDATE' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.hold.update' }, 'FM_AHR_RESET' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.hold.reset' }, diff --git a/Open-ILS/xul/staff_client/chrome/content/util/network.js b/Open-ILS/xul/staff_client/chrome/content/util/network.js index 501f73c678..227568e1dc 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/network.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/network.js @@ -16,17 +16,15 @@ util.network.prototype = { 'NETWORK_FAILURE' : null, 'simple_request' : function(method_id,params,f,override_params) { + //var obj = this; + //var sparams = js2JSON(params); + //obj.error.sdump('D_SES','simple_request '+ method_id +' '+obj.error.pretty_print(sparams.slice(1,sparams.length-1))+ + // '\noverride_params = ' + override_params + '\n'); if (typeof api[method_id] == 'undefined') throw( 'Method not found for ' + method_id ); var secure = true; if (typeof api[method_id].secure != 'undefined') secure = api[method_id].secure; return this.request(api[method_id].app,api[method_id].method,params,f,override_params,{ 'secure' : secure, 'method_id' : method_id }); }, - 'cached_request' : function(method_id,params,f,override_params) { - if (typeof api[method_id] == 'undefined') throw( 'Method not found for ' + method_id ); - var secure = true; if (typeof api[method_id].secure != 'undefined') secure = api[method_id].secure; - return this.request(api[method_id].app,api[method_id].method,params,f,override_params,{ 'secure' : secure, 'want_cached' : true, 'method_id' : method_id }); - }, - 'get_result' : function (req) { var obj = this; var result; @@ -47,69 +45,23 @@ util.network.prototype = { return result; }, - 'is_cacheable' : function(method_id) { - return (api[method_id].cacheable); - }, - 'request' : function (app,name,params,f,override_params,_params) { var obj = this; + + //var sparams = js2JSON(params); + //obj.error.sdump('D_SES','request '+ app + ' ' + name +' '+obj.error.pretty_print(sparams.slice(1,sparams.length-1))+ + // '\noverride_params = ' + override_params + '\n_params = ' + _params + '\n'); try { - if (_params && _params.want_cached) if ( this.is_cacheable(_params.method_id) ) { - JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); - var key = (app + '+' + name + '+' + js2JSON(params)).replace(/\./g,'_'); - var x = data.cached_request[key]; - if (x) { - obj.error.sdump('D_CACHE','Cached request found for key = \n' + key + '\n' + js2JSON(x) + '\n'); - switch(x.status) { - case 'pending' : - if ( Number(new Date()) - Number(x.status_time) > 60000 ) break; // if pending request is taking too long - if (f) { // Setup a self-destroying observer on the pending request to handle this request - obj.error.sdump('D_CACHE','Cached request pending, adding watch to handle current asynchronous request. key = \n' + key + '\n'); - var id = data.observers.add('cached_request.'+key+'.status',function(p,o,n) { - obj.error.sdump('D_OBSERVERS','Entering watch function for key = \n' + key + '\np = ' + p + '\no = ' + js2JSON(o) + '\nn = ' + js2JSON(n) + '\nx = ' + js2JSON(x) + '\n'); - if (n == 'complete') { - obj.error.sdump('D_CACHE','Cached request completed for key = \n' + key + '\nNow calling a previous async request watching this one.\n'); - f( { 'getResultObject' : function() { return JSON2js( js2JSON( x.request ) ); } } ); - setTimeout( function() { try { data.observers.remove(id); } catch(E) { alert(E); } }, 0 ); - } - return n; - } - ); - return null; - } else { - obj.error.sdump('D_CACHE','Pending request and synchronous request collision with key = \n' + key + '\nFalling through...\n'); - } - break; - case 'complete' : - if ( Number( new Date() ) < x.expire_time ) { - if (f) { - obj.error.sdump('D_CACHE','Cached request found completed, handling asynchronous request now. key = \n' + key + '\n'); - f( { 'getResultObject' : function() { return JSON2js( js2JSON( x.request ) ); } } ); - return null; - } else { - obj.error.sdump('D_CACHE','Cached request found completed, key = \n' + key + '\nreturning value =\n' + x.request + '\n'); - return JSON2js( js2JSON( x.request ) ); // FIXME -- cloning the object is a workaround, otherwise instanceOf somehow silently fails - } - } else { - obj.error.sdump('D_CACHE','Cached request found completed, however, it has expired. key = \n' + key + '\nFalling through...\n'); - } - break; - } + var request = this._request(app,name,params,f,override_params,_params); + if (request) { + return this.get_result(request); } else { - obj.error.sdump('D_CACHE','Cached request not found for key = \n' + key + '\n'); + return null; } - } - - var request = this._request(app,name,params,f,override_params,_params); - if (request) { - return this.get_result(request); - } else { - return null; - } - + } catch(E) { alert(E); } @@ -119,20 +71,10 @@ util.network.prototype = { var obj = this; try { var sparams = js2JSON(params); - obj.error.sdump('D_SES','request '+app+' '+name+' '+obj.error.pretty_print(sparams.slice(1,sparams.length-1))+ + obj.error.sdump('D_SES','_request '+app+' '+name+' '+obj.error.pretty_print(sparams.slice(1,sparams.length-1))+ '\noverride_params = ' + override_params + '\n_params = ' + _params + '\nResult #' + (++obj.link_id) + ( f ? ' asynced' : ' synced' ) ); - var key; var x; var data; - if (_params && obj.is_cacheable(_params.method_id)) { - JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.init({'via':'stash'}); - key = (app + '+' + name + '+' + js2JSON(params)).replace(/\./g,'_'); - data.cached_request[key] = { 'test' : 'test', 'status' : 'pending', 'status_time' : Number(new Date()) }; - data.stash('cached_request'); - x = data.cached_request[key]; - obj.error.sdump('D_CACHE','Current request is cacheable, setting pending status for key = \n' + key + '\nUpdating cache with ' + js2JSON(x) + '\n'); - } - var request = new RemoteRequest( app, name ); if (_params && _params.secure) { request.setSecure(true); @@ -159,12 +101,6 @@ util.network.prototype = { req = obj.rerequest_on_override(app,name,params,req,override_params,_params); } req = obj.check_for_offline(app,name,params,req,override_params,_params); - if (_params && obj.is_cacheable(_params.method_id)) { - x.request = obj.get_result(req); - x.status = 'complete'; x.status_time = Number(new Date()); x.expire_time = Number(x.status_time) + api[_params.method_id].ttl; - data.stash('cached_request'); - obj.error.sdump('D_CACHE','Previously pending cached request is now complete for key = \n' + key + '\nUpdating cache with ' + js2JSON(x) + '\n'); - } f(req); obj.NETWORK_FAILURE = null; } catch(E) { @@ -201,12 +137,6 @@ util.network.prototype = { } request = obj.check_for_offline(app,name,params,request,override_params,_params); obj.NETWORK_FAILURE = null; - if (_params && obj.is_cacheable(_params.method_id)) { - x.request = result; - x.status = 'complete'; x.status_time = Number(new Date()); x.expire_time = Number(x.status_time) + api[_params.method_id].ttl; - data.stash('cached_request'); - obj.error.sdump('D_CACHE','Previously pending cached request is now complete for key = \n' + key + '\nUpdating cache with ' + js2JSON(x) + '\n'); - } return request; } diff --git a/Open-ILS/xul/staff_client/server/circ/checkout.js b/Open-ILS/xul/staff_client/server/circ/checkout.js index c510de1dc6..29d143ddc1 100644 --- a/Open-ILS/xul/staff_client/server/circ/checkout.js +++ b/Open-ILS/xul/staff_client/server/circ/checkout.js @@ -232,7 +232,7 @@ circ.checkout.prototype = { this.check_disable(); - var robj = obj.network.cached_request( + var robj = obj.network.simple_request( 'FM_CIRC_COUNT_RETRIEVE_VIA_USER', [ ses(), obj.patron_id ] ); diff --git a/Open-ILS/xul/staff_client/server/main/data.xul b/Open-ILS/xul/staff_client/server/main/data.xul index 97493d7584..be78897eab 100644 --- a/Open-ILS/xul/staff_client/server/main/data.xul +++ b/Open-ILS/xul/staff_client/server/main/data.xul @@ -190,23 +190,7 @@ g.data.stash('session'); g.data.on_complete = function () { - g.data.stash('list','hash','tree','temp','cached_request'); - - setInterval( - function() { - try { - var remove_me = []; - var n = Number( new Date() ); - for (var i in g.data.cached_request) { - if (g.data.cached_request[i].expire_time < n && g.data.cached_request[i].status != 'pending') remove_me.push(i); - } - dump('trimming ' + remove_me.length + ' requests from cache\n'); - for (var i in remove_me) delete g.data.cached_request[i]; - } catch(E) { - alert(E); - } - }, 180000 - ); + g.data.stash('list','hash','tree','temp'); g.data._debug_stash(); diff --git a/Open-ILS/xul/staff_client/server/patron/display.js b/Open-ILS/xul/staff_client/server/patron/display.js index 59542ddaba..cc60183cd2 100644 --- a/Open-ILS/xul/staff_client/server/patron/display.js +++ b/Open-ILS/xul/staff_client/server/patron/display.js @@ -589,7 +589,6 @@ patron.display.prototype = { 'refresh_all' : function() { var obj = this; - obj.OpenILS.data.cached_request = {}; obj.OpenILS.data.stash('cached_request'); /* FIXME - do a more selective purging here */ obj.controller.view.patron_name.setAttribute( 'value','Retrieving...' ); diff --git a/Open-ILS/xul/staff_client/server/patron/info_notes.xul b/Open-ILS/xul/staff_client/server/patron/info_notes.xul index 41179fd613..6f735fa40b 100644 --- a/Open-ILS/xul/staff_client/server/patron/info_notes.xul +++ b/Open-ILS/xul/staff_client/server/patron/info_notes.xul @@ -71,7 +71,7 @@ g.notes = g.network.simple_request('FM_AUN_RETRIEVE_ALL',[ ses(), { 'patronid' : g.patron_id } ]).reverse(); g.new_note = false; } else { - g.notes = g.network.cached_request('FM_AUN_RETRIEVE_ALL',[ ses(), { 'patronid' : g.patron_id } ]).reverse(); + g.notes = g.network.simple_request('FM_AUN_RETRIEVE_ALL',[ ses(), { 'patronid' : g.patron_id } ]).reverse(); } } diff --git a/Open-ILS/xul/staff_client/server/patron/summary.js b/Open-ILS/xul/staff_client/server/patron/summary.js index 15b3778098..6c83512493 100644 --- a/Open-ILS/xul/staff_client/server/patron/summary.js +++ b/Open-ILS/xul/staff_client/server/patron/summary.js @@ -127,7 +127,7 @@ patron.summary.prototype = { function(e) { return function() { e.setAttribute('value','...'); - obj.network.cached_request( + obj.network.simple_request( 'FM_MOUS_RETRIEVE', [ ses(), obj.patron.id() ], function(req) { @@ -171,7 +171,7 @@ patron.summary.prototype = { var e4 = document.getElementById( 'patron_long_overdue' ); if (e4) e4.setAttribute('value','...'); var e5 = document.getElementById( 'patron_lost' ); if (e5) e5.setAttribute('value','...'); var e6 = document.getElementById( 'patron_noncat' ); if (e6) e6.setAttribute('value','...'); - obj.network.cached_request( + obj.network.simple_request( 'FM_CIRC_COUNT_RETRIEVE_VIA_USER', [ ses(), obj.patron.id() ], function(req) { diff --git a/Open-ILS/xul/staff_client/server/patron/util.js b/Open-ILS/xul/staff_client/server/patron/util.js index 6165fcee12..aaaee6a09a 100644 --- a/Open-ILS/xul/staff_client/server/patron/util.js +++ b/Open-ILS/xul/staff_client/server/patron/util.js @@ -472,7 +472,7 @@ patron.util.std_map_row_to_columns = function(error_value) { patron.util.retrieve_au_via_id = function(session, id, f) { JSAN.use('util.network'); var network = new util.network(); - var patron_obj = network.cached_request( + var patron_obj = network.simple_request( 'FM_AU_RETRIEVE_VIA_ID', [ session, id ], f @@ -483,7 +483,7 @@ patron.util.retrieve_au_via_id = function(session, id, f) { patron.util.retrieve_name_via_id = function(session, id) { JSAN.use('util.network'); var network = new util.network(); - var parts = network.cached_request( + var parts = network.simple_request( 'BLOB_AU_PARTS_RETRIEVE', [ session, id, ['family_name', 'first_given_name', 'second_given_name', 'home_ou' ] ] ); @@ -493,7 +493,7 @@ patron.util.retrieve_name_via_id = function(session, id) { patron.util.retrieve_fleshed_au_via_id = function(session, id) { JSAN.use('util.network'); var network = new util.network(); - var patron_obj = network.cached_request( + var patron_obj = network.simple_request( 'FM_AU_FLESHED_RETRIEVE_VIA_ID', [ session, id ] ); @@ -504,7 +504,7 @@ patron.util.retrieve_fleshed_au_via_id = function(session, id) { patron.util.retrieve_fleshed_au_via_barcode = function(session, id) { JSAN.use('util.network'); var network = new util.network(); - var patron_obj = network.cached_request( + var patron_obj = network.simple_request( 'FM_AU_RETRIEVE_VIA_BARCODE', [ session, id ] ); @@ -546,10 +546,10 @@ patron.util.set_penalty_css = function(patron) { removeCSSClass(document.documentElement,'PATRON_NET_ACCESS_3'); JSAN.use('util.network'); var net = new util.network(); - net.cached_request('FM_MOUS_RETRIEVE',[ ses(), patron.id() ], function(req) { + net.simple_request('FM_MOUS_RETRIEVE',[ ses(), patron.id() ], function(req) { if (req.getResultObject().balance_owed() > 0) addCSSClass(document.documentElement,'PATRON_HAS_BILLS'); }); - net.cached_request('FM_CIRC_COUNT_RETRIEVE_VIA_USER',[ ses(), patron.id() ], function(req) { + net.simple_request('FM_CIRC_COUNT_RETRIEVE_VIA_USER',[ ses(), patron.id() ], function(req) { try { var co = req.getResultObject(); if (co.overdue > 0 || co.long_overdue > 0) addCSSClass(document.documentElement,'PATRON_HAS_OVERDUES'); @@ -557,7 +557,7 @@ patron.util.set_penalty_css = function(patron) { alert(E); } }); - net.cached_request('FM_AUN_RETRIEVE_ALL',[ ses(), { 'patronid' : patron.id() } ], function(req) { + net.simple_request('FM_AUN_RETRIEVE_ALL',[ ses(), { 'patronid' : patron.id() } ], function(req) { var notes = req.getResultObject(); if (notes.length > 0) addCSSClass(document.documentElement,'PATRON_HAS_NOTES'); }); -- 2.11.0