2 require '../oils_header.pl';
3 use strict; use warnings;
4 use Time::HiRes qw/time usleep/;
6 use OpenSRF::Utils::JSON;
7 use OpenILS::Utils::CStoreEditor;
10 #-----------------------------------------------------------------------------
11 # Does a checkout, renew, and checkin
12 #-----------------------------------------------------------------------------
14 my @recs = (1,2,3,4,5,6,7,8,9,10);
16 osrf_connect(shift() || '/openils/conf/opensrf_core.xml');
18 my $e = OpenILS::Utils::CStoreEditor->new;
21 my($node, $path) = @_;
22 #my $res = $node->findnodes($path);
23 my $res = $node->find($path);
24 return '' unless $res and $res->[0];
25 return $res->[0]->textContent;
31 isbn => xptext($xml, '*[@tag="020"]/*[@code="a"]'),
32 upc => xptext($xml,'*[@tag="024"]/*[@code="a"]'),
33 issn => xptext($xml,'*[@tag="022"]/*[@code="a"]'),
34 title => xptext($xml,'*[@tag="245"]/*[@code="a"]'),
35 author => xptext($xml,'*[@tag="100"]/*[@code="a"]'),
36 publisher => xptext($xml,'*[@tag="260"]/*[@code="b"]'),
37 pubdate => xptext($xml,'*[@tag="260"]/*[@code="c"]'),
38 edition => xptext($xml,'*[@tag="250"]/*[@code="a"]'),
46 my $ses1 = OpenSRF::AppSession->create('open-ils.cstore');
47 my $ses2 = OpenSRF::AppSession->create('open-ils.cstore');
48 my $ses3 = OpenSRF::AppSession->create('open-ils.cstore');
49 my ($req1, $req2, $req3);
53 my ($id1, $id2, $id3) = (pop @recs, pop @recs, pop @recs);
55 for my $r ($req1, $req2, $req3) {
57 my $data = $r->gather(1);
58 my $xml = XML::LibXML->new->parse_string($data->{'unapi.bre'});
59 $xml = $xml->documentElement;
60 my $attrs = get_bib_attrs($xml);
61 my $rec_id = xptext($xml,'*[@tag="901"]/*[@code="c"]');
62 $records{$rec_id}{$_} = $attrs->{$_} for keys %$attrs;
65 for my $volnode ($xml->findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]')) {
68 $vol->{label} = $volnode->getAttribute('label');
69 for my $copynode ($volnode->getElementsByLocalName('copy')) {
71 $copy->{barcode} = $copynode->getAttribute('barcode');
72 push(@{$vol->{copies}}, $copy);
74 push(@{$records{$rec_id}->{volumes}}, $vol);
80 $req1 = ($id1) ? $ses1->request('open-ils.cstore.json_query', {from => ['unapi.bre', $id1, 'marcxml', 'record', '{holdings_xml,acp}', 'CONS']}) : undef;
81 $req2 = ($id2) ? $ses1->request('open-ils.cstore.json_query', {from => ['unapi.bre', $id2, 'marcxml', 'record', '{holdings_xml,acp}', 'CONS']}) : undef;
82 $req3 = ($id3) ? $ses1->request('open-ils.cstore.json_query', {from => ['unapi.bre', $id3, 'marcxml', 'record', '{holdings_xml,acp}', 'CONS']}) : undef;
86 for my $r ($req1, $req2, $req3) {
88 my $data = $r->gather(1);
89 my $xml = XML::LibXML->new->parse_string($data->{'unapi.bre'});
90 $xml = $xml->documentElement;
91 my $attrs = get_bib_attrs($xml);
92 my $rec_id = xptext($xml,'*[@tag="901"]/*[@code="c"]');
93 $records{$rec_id}{$_} = $attrs->{$_} for keys %$attrs;
96 for my $volnode ($xml->findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]')) {
99 $vol->{label} = $volnode->getAttribute('label');
100 for my $copynode ($volnode->getElementsByLocalName('copy')) {
102 $copy->{barcode} = $copynode->getAttribute('barcode');
103 push(@{$vol->{copies}}, $copy);
105 push(@{$records{$rec_id}->{volumes}}, $vol);
111 my $duration = time() - $start;
113 for my $rec_id (keys %records) {
114 my $rec = $records{$rec_id};
115 print sprintf("%d [%s] has %d volumes and %d copies\n",
116 $rec_id, $rec->{title},
117 scalar(@{$rec->{volumes}}),
118 scalar(map { @{$_->{copies}} } @{$rec->{volumes}}));
121 #note, unapi.biblio_record_entry_feed per record performs the same as unapi.bre pre record
122 print "\nunapi 'unapi.bre' duration is $duration\n\n";
131 for my $rec_id (@recs) {
133 my $ses = OpenSRF::AppSession->create('open-ils.cstore');
134 my $req = $ses->request(
135 'open-ils.cstore.json_query',
136 {from => ['unapi.bre', $rec_id, 'marcxml', 'record', '{holdings_xml,acp}', 'CONS']});
141 for my $req (@reqs) {
143 my $data = $req->gather(1);
144 my $xml = XML::LibXML->new->parse_string($data->{'unapi.bre'});
145 $xml = $xml->documentElement;
146 my $attrs = get_bib_attrs($xml);
147 my $rec_id = xptext($xml,'*[@tag="901"]/*[@code="c"]');
148 $records{$rec_id}{$_} = $attrs->{$_} for keys %$attrs;
151 for my $volnode ($xml->findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]')) {
154 $vol->{label} = $volnode->getAttribute('label');
155 for my $copynode ($volnode->getElementsByLocalName('copy')) {
157 $copy->{barcode} = $copynode->getAttribute('barcode');
158 push(@{$vol->{copies}}, $copy);
160 push(@{$records{$rec_id}->{volumes}}, $vol);
164 my $duration = time() - $start;
166 for my $rec_id (keys %records) {
167 my $rec = $records{$rec_id};
168 print sprintf("%d [%s] has %d volumes and %d copies\n",
169 $rec_id, $rec->{title},
170 scalar(@{$rec->{volumes}}),
171 scalar(map { @{$_->{copies}} } @{$rec->{volumes}}));
174 #note, unapi.biblio_record_entry_feed per record performs the same as unapi.bre pre record
175 print "\nunapi 'unapi.bre' spread duration is $duration\n\n";
184 my $data = $e->json_query({from => ['unapi.biblio_record_entry_feed', "{".join(',',@recs)."}", 'marcxml', '{holdings_xml,acp}', 'CONS']})->[0];
185 my $xml = XML::LibXML->new->parse_string($data->{'unapi.biblio_record_entry_feed'});
188 for my $rec_xml ($xml->documentElement->getElementsByLocalName('record')) {
190 my $attrs = get_bib_attrs($rec_xml);
191 my $rec_id = xptext($rec_xml,'*[@tag="901"]/*[@code="c"]');
192 #print "REC = $rec_xml : $rec_id : " . $attrs->{title} . "\n" . $rec_xml->toString . "\n";
193 $records{$rec_id}{$_} = $attrs->{$_} for keys %$attrs;
196 for my $volnode ($rec_xml->findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]')) {
199 $vol->{label} = $volnode->getAttribute('label');
200 for my $copynode ($volnode->getElementsByLocalName('copy')) {
202 $copy->{barcode} = $copynode->getAttribute('barcode');
203 push(@{$vol->{copies}}, $copy);
205 push(@{$records{$rec_id}->{volumes}}, $vol);
209 my $duration = time() - $start;
211 for my $rec_id (keys %records) {
212 my $rec = $records{$rec_id};
213 print sprintf("%d [%s] has %d volumes and %d copies\n",
214 $rec_id, $rec->{title},
215 scalar(@{$rec->{volumes}}),
216 scalar(map { @{$_->{copies}} } @{$rec->{volumes}}));
218 print "\nunapi 'batch feed' duration is $duration\n\n";
229 bre => ['call_numbers'],
230 acn => ['copies', 'uris'],
231 acp => ['location', 'stat_cat_entries', 'parts'],
232 ascecm => ['stat_cat', 'stat_cat_entry'],
238 for my $rec_id (@recs) {
239 my $ses = OpenSRF::AppSession->create('open-ils.cstore');
240 my $req = $ses->request(
241 'open-ils.cstore.direct.biblio.record_entry.search', {id => $rec_id}, $query);
245 $records{$_}{counts} = $e->json_query({from => ['asset.record_copy_count', 1, $_, 0]})->[0] for @recs;
246 for my $req (@reqs) {
247 my $bre = $req->gather(1);
248 my $xml = XML::LibXML->new->parse_string($bre->marc)->documentElement;
249 my $attrs = get_bib_attrs($xml);
250 $records{$bre->id}{record} = $bre;
251 $records{$bre->id}{$_} = $attrs->{$_} for keys %$attrs;
254 my $duration = time() - $start;
256 for my $rec_id (keys %records) {
257 my $rec = $records{$rec_id};
258 print sprintf("%d [%s] has %d volumes and %d copies\n",
259 $rec_id, $rec->{title},
260 scalar(@{$rec->{record}->call_numbers}),
261 scalar(map { @{$_->copies} } @{$rec->{record}->call_numbers}));
264 print "\n'direct' spread calls processing duration is $duration\n\n";
274 my $ses1 = OpenSRF::AppSession->create('open-ils.cstore');
275 my $ses2 = OpenSRF::AppSession->create('open-ils.cstore');
276 my $ses3 = OpenSRF::AppSession->create('open-ils.cstore');
277 my ($req1, $req2, $req3);
282 bre => ['call_numbers'],
283 acn => ['copies', 'uris'],
284 acp => ['location', 'stat_cat_entries', 'parts'],
285 ascecm => ['stat_cat', 'stat_cat_entry'],
292 my ($id1, $id2, $id3) = (pop @recs, pop @recs, pop @recs);
294 for my $r ($req1, $req2, $req3) {
296 my $bre = $r->gather(1);
297 my $xml = XML::LibXML->new->parse_string($bre->marc)->documentElement;
298 my $attrs = get_bib_attrs($xml);
299 $records{$bre->id}{record} = $bre;
300 $records{$bre->id}{$_} = $attrs->{$_} for keys %$attrs;
303 $req1 = ($id1) ? $ses1->request('open-ils.cstore.direct.biblio.record_entry.search', {id => $id1}, $query) : undef;
304 $req2 = ($id2) ? $ses1->request('open-ils.cstore.direct.biblio.record_entry.search', {id => $id2}, $query) : undef;
305 $req3 = ($id3) ? $ses1->request('open-ils.cstore.direct.biblio.record_entry.search', {id => $id3}, $query) : undef;
308 $records{$_}{counts} = $e->json_query({from => ['asset.record_copy_count', 1, $_, 0]})->[0] for @recs;
313 for my $r ($req1, $req2, $req3) {
315 my $bre = $r->gather(1);
316 my $xml = XML::LibXML->new->parse_string($bre->marc)->documentElement;
317 my $attrs = get_bib_attrs($xml);
318 $records{$bre->id}{record} = $bre;
319 $records{$bre->id}{$_} = $attrs->{$_} for keys %$attrs;
323 my $duration = time() - $start;
325 for my $rec_id (keys %records) {
326 my $rec = $records{$rec_id};
327 print sprintf("%d [%s] has %d volumes and %d copies\n",
328 $rec_id, $rec->{title},
329 scalar(@{$rec->{record}->call_numbers}),
330 scalar(map { @{$_->copies} } @{$rec->{record}->call_numbers}));
333 print "\n'direct' calls processing duration is $duration\n\n";
336 for (0..1) { direct(@recs); unapi(@recs); unapi_batch(@recs); unapi_spread(@recs); direct_spread(@recs); }