From acb7766b9f2af3eb0bba4ed6f724dcc760c4ffdd Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 23 Sep 2010 23:38:10 +0000 Subject: [PATCH] Stopping the leak git-svn-id: svn://svn.open-ils.org/ILS/trunk@17937 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Circ/Holds.pm | 110 ++++++++++++++++++++- .../Application/Storage/Publisher/action.pm | 2 +- Open-ILS/web/js/dojo/openils/BibTemplate.js | 10 +- Open-ILS/web/js/dojo/openils/PermaCrud.js | 44 ++++++++- 4 files changed, 153 insertions(+), 13 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index 7dde2ef536..877ca67e27 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -24,6 +24,7 @@ use OpenSRF::EX qw(:try); use OpenILS::Perm; use OpenILS::Event; use OpenSRF::Utils; +use OpenSRF::AppSession; use OpenSRF::Utils::Logger qw(:logger); use OpenILS::Utils::CStoreEditor q/:funcs/; use OpenILS::Utils::PermitHold; @@ -1265,22 +1266,123 @@ sub print_hold_pull_list { my $hold_ids = $U->storagereq( 'open-ils.storage.direct.action.hold_request.pull_list.id_list.current_copy_circ_lib.status_filtered.atomic', $org_id, 10000); - + return undef unless @$hold_ids; $client->status(new OpenSRF::DomainObject::oilsContinueStatus); - + # Holds will /NOT/ be in order after this ... my $holds = $e->search_action_hold_request({id => $hold_ids}, {substream => 1}); $client->status(new OpenSRF::DomainObject::oilsContinueStatus); - + # ... so we must resort. my $hold_map = +{map { $_->id => $_ } @$holds}; my $sorted_holds = []; push @$sorted_holds, $hold_map->{$_} foreach @$hold_ids; - + return $U->fire_object_event( undef, "ahr.format.pull_list", $sorted_holds, $org_id ); + +} + +__PACKAGE__->register_method( + method => "print_hold_pull_list_stream", + api_name => "open-ils.circ.hold_pull_list.print.stream", + signature => { + desc => 'Returns a stream of fleshed holds', + params => [ + { desc => 'Authtoken', type => 'string'}, + { desc => 'Hash of optional param: Org unit ID (defaults to workstation org unit), limit, offset, sort (array of: acplo.position, call_number, request_time)', + type => 'object' + }, + ], + return => { + desc => 'A stream of fleshed holds', + type => 'object' + } + } +); + +sub print_hold_pull_list_stream { + my($self, $client, $auth, $params) = @_; + + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; + + delete($$params{org_id}) unless (int($$params{org_id})); + delete($$params{limit}) unless (int($$params{limit})); + delete($$params{offset}) unless (int($$params{offset})); + + $$params{org_id} = (defined $$params{org_id}) ? $$params{org_id}: $e->requestor->ws_ou; + return $e->die_event unless $e->allowed('VIEW_HOLD', $$params{org_id }); + + my $sort = 'ahr.request_time'; + if ($$params{sort} && @{ $$params{sort} }) { + $sort = ''; + for my $s (@{ $$params{sort} }) { + if ($s eq 'acplo.position') { + $s = 'coalesce(acplo.position,999)'; + } elsif ($s eq 'call_number') { + $s = 'acn.label'; + } elsif ($s eq 'request_time') { + $s = 'ahr.request_time'; + } else { + $s = ''; + } + + $sort .= ', ' if ($sort); + $sort .= $s; + } + } + + my $req = OpenSRF::AppSession->create('open-ils.cstore')->request( + 'open-ils.cstore.direct.action.hold_request', + { capture_time => undef, + cancel_time => undef, + '-or' => [ + { expire_time => undef }, + { expire_time => { '>' => 'now' } } + ] + },{ + flesh => 3, + flesh_fields => { + ahr => [ "usr","current_copy" ], + au => [ "card" ], + acp => [ "location", "call_number" ], + acn => [ "record" ] + }, + join => { + acp => { + field => 'id', + fkey => 'current_copy', + filter => { circ_lib => $$params{org_id}, status => [0,7] }, + join => { + acn => { + field => 'id', + fkey => 'call_number' + }, + acplo => { + field => 'org', + fkey => 'circ_lib', + type => 'left' + } + } + } + }, + order_by => $sort, + ($$params{limit} ? (limit => $$params{limit}) : ()), + ($$params{offset} ? (offset => $$params{offset}) : ()), + } + ); + + while (my $resp = $req->recv( timeout => 180 )) { + if ($req->failed) { + throw OpenSRF::EX::ERROR ($self->failed()->stringify()) + } + $self->respond( $resp->content ); + } + + return $self->respond_complete; } diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm index eff5a0a3f9..471adc80f6 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm @@ -1294,7 +1294,7 @@ sub new_hold_copy_targeter { my %circ_lib_map = map { (''.$_->circ_lib => 1) } @$all_copies; my $circ_lib_list = [keys %circ_lib_map]; - my $cstore = OpenSRF::AppSession->connect('open-ils.cstore'); + my $cstore = OpenSRF::AppSession->create('open-ils.cstore'); # Grab the "biggest" loop for this hold so far my $current_loop = $cstore->request( diff --git a/Open-ILS/web/js/dojo/openils/BibTemplate.js b/Open-ILS/web/js/dojo/openils/BibTemplate.js index 790d16a60e..027e90deb8 100644 --- a/Open-ILS/web/js/dojo/openils/BibTemplate.js +++ b/Open-ILS/web/js/dojo/openils/BibTemplate.js @@ -36,6 +36,9 @@ if(!dojo._hasResource["openils.BibTemplate"]) { this.locale = kwargs.locale || OpenSRF.locale || 'en-US'; this.nodelay = kwargs.delay == false; + if (this.xml && this.xml instanceof String) + this.xml = dojox.xml.parser.parse(this.xml); + this.mode = 'biblio-record_entry'; this.default_datatype = 'marcxml-uris'; if (kwargs.metarecord) { @@ -56,12 +59,11 @@ if(!dojo._hasResource["openils.BibTemplate"]) { }, textContent : function (node) { - var content = ''; if (node) { - if(window.ActiveXObject) content = node.text; - else content = node.textContent; + if (node instanceof HTMLElement) return node.innerText || node.textContent; + return dojox.xml.parser.textContent(node); } - return content; + return ''; }, render : function() { diff --git a/Open-ILS/web/js/dojo/openils/PermaCrud.js b/Open-ILS/web/js/dojo/openils/PermaCrud.js index 834c6cd8d0..f571d7d66d 100644 --- a/Open-ILS/web/js/dojo/openils/PermaCrud.js +++ b/Open-ILS/web/js/dojo/openils/PermaCrud.js @@ -26,11 +26,13 @@ if(!dojo._hasResource["openils.PermaCrud"]) { session : null, authtoken : null, connnected : false, + authoritative : false, constructor : function ( kwargs ) { kwargs = kwargs || {}; this.authtoken = kwargs.authtoken; + this.authoritative = kwargs.authoritative; this.session = kwargs.session || @@ -66,7 +68,41 @@ if(!dojo._hasResource["openils.PermaCrud"]) { return false; } }, - + + _session_request : function ( args /* hash */, commitOnComplete /* set to true, else no */ ) { + + var me = this; + var endstyle = 'rollback'; + if (commitOnComplete) endstyle = 'commit'; + + if (me.authoritative) { + if (!me.connected) me.connect(); + if (args.timeout && !args.oncomplete && !args.onresponse) { // pure sync call + args.oncomplete = function (r) { + me.session.request('open-ils.pcrud.transaction.' + endstyle, me.auth()); + me.session.disconnect(); + me.disconnect(); + }; + } else if (args.oncomplete) { // there's an oncomplete, fire that, and then end the transaction + var orig_oncomplete = args.oncomplete; + args.oncomplete = function (r) { + var ret; + try { + ret = orig_oncomplete(r); + } finally { + me.session.request('open-ils.pcrud.transaction.' + endstyle, me.auth()); + me.session.disconnect(); + me.disconnect(); + } + return ret; + }; + } + + if (me.authoritative) me.session.request('open-ils.pcrud.transaction.begin', me.auth() ); + + return me.session.request( args ); + + }, retrieve : function ( fm_class /* Fieldmapper class hint */, id /* Fieldmapper object primary key value */, opts /* Option hash */) { if(!opts) opts = {}; @@ -80,7 +116,7 @@ if(!dojo._hasResource["openils.PermaCrud"]) { if (!opts.async && !opts.timeout) req_hash.timeout = 10; var _pcrud = this; - var req = this.session.request( req_hash ); + var req = this._session_request( req_hash ); if (!req.onerror) req.onerror = function (r) { throw js2JSON(r); }; @@ -129,7 +165,7 @@ if(!dojo._hasResource["openils.PermaCrud"]) { if (!opts.async && !opts.timeout) req_hash.timeout = 10; var _pcrud = this; - var req = this.session.request( req_hash ); + var req = this._session_request( req_hash ); if (!req.onerror) req.onerror = function (r) { throw js2JSON(r); }; @@ -175,7 +211,7 @@ if(!dojo._hasResource["openils.PermaCrud"]) { if (!opts.async && !opts.timeout) req_hash.timeout = 10; var _pcrud = this; - var req = this.session.request( req_hash ); + var req = this._session_request( req_hash ); if (!req.onerror) req.onerror = function (r) { throw js2JSON(r); }; -- 2.11.0