Bugzilla – Attachment 153564 Details for
Bug 34282
ILL batches - availability checking has issues
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34282: Follow-up to fix multiple requests causing high server load, squash later
Bug-34282-Follow-up-to-fix-multiple-requests-causi.patch (text/plain), 6.16 KB, created by
Pedro Amorim
on 2023-07-17 15:57:35 UTC
(
hide
)
Description:
Bug 34282: Follow-up to fix multiple requests causing high server load, squash later
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2023-07-17 15:57:35 UTC
Size:
6.16 KB
patch
obsolete
>From b93867a52294eecdd6cd7ab0e3060c8254b680f2 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Mon, 17 Jul 2023 15:56:39 +0000 >Subject: [PATCH] Bug 34282: Follow-up to fix multiple requests causing high > server load, squash later > >--- > .../intranet-tmpl/prog/js/ill-batch-modal.js | 103 ++++++++---------- > 1 file changed, 45 insertions(+), 58 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js b/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js >index 20d54781bc..ed53610578 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js >@@ -86,9 +86,6 @@ > updateTable(); > updateRowCount(); > updateProcessTotals(); >- if (ill_check_availability_syspref == 1){ >- checkAvailability(); >- } > } > } > ); >@@ -237,55 +234,28 @@ > }); > }; > >- // Identify items that can have their availability checked, and do it >- function checkAvailability() { >- // Only proceed if we've got services that can check availability >- if (!batch_availability_services || batch_availability_services.length === 0) return; >- var toCheck = tableContent.data; >- toCheck.forEach(function (row) { >- if ( >- !row.url && >- Object.keys(row.metadata).length > 0 && >- !availabilitySent[row.value] >- ) { >- availabilitySent[row.value] = 1; >- getAvailability(row); >- } >- }); >- }; >- >- // Check availability services for immediate availability, if found, >- // create a link in the table linking to the item >- function getAvailability(row) { >+ async function populateAvailability(row) { > let metadata = row.metadata; >- // Prep the metadata for passing to the availability plugins >+ > let availability_object = {}; > if (metadata.issn) availability_object['issn'] = metadata.issn; > if (metadata.doi) availability_object['doi'] = metadata.doi; > if (metadata.pubmedid) availability_object['pubmedid'] = metadata.pubmedid; >- var prepped = encodeURIComponent(base64EncodeUnicode(JSON.stringify(availability_object))); >- row.av_hits = []; >- batch_availability_services.map(async (service) => { >- window.doApiRequest( >- service.endpoint + prepped >- ) >- .then(function (response) { >- return response.json(); >- }) >- .then(function (data) { >- if (data.results.search_results && data.results.search_results.length > 0) { >- var result = data.results.search_results[0]; >- row.av_hits.push({name:service.name, url:result.url}); >- return row; >- }else { >- row.av_hits.push({ name: service.name, empty: 1 }) >- } >- }) >- .then(function (response) { >- updateTable(); >- }); >- }); >- // } >+ >+ // Check each service and use the first results we get, if any >+ var av_hits = []; >+ for (const service of batch_availability_services){ >+ var prepped = encodeURIComponent(base64EncodeUnicode(JSON.stringify(availability_object))); >+ >+ var endpoint = service.endpoint + prepped; >+ var availability = await getAvailability(endpoint); >+ if (availability.results.search_results && availability.results.search_results.length > 0) { >+ av_hits.push({name: service.name, url: availability.results.search_results[0].url}); >+ }else{ >+ av_hits.push({ name: service.name, empty:1 }); >+ } >+ }; >+ return av_hits; > }; > > // Help btoa with > 8 bit strings >@@ -689,6 +659,7 @@ > } else if (alreadyInDeduped.length === 0) { > row.metadata = {}; > row.failed = {}; >+ row.availability_hits = {}; > row.requestId = null; > deduped.push(row); > } >@@ -739,6 +710,16 @@ > } catch (e) { > row.failed = ill_populate_failed; > } >+ >+ if (ill_check_availability_syspref == 1){ >+ try { >+ var availability = await populateAvailability(row); >+ row.availability_hits = availability || {}; >+ } catch (e) { >+ //do nothing >+ } >+ } >+ > newData[i] = row; > tableContent.data = newData; > } >@@ -774,6 +755,11 @@ > } > }; > >+ async function getAvailability(endpoint) { >+ var response = await debounce(doApiRequest)(endpoint); >+ return response.json(); >+ }; >+ > async function getMetadata(endpoint) { > var response = await debounce(doApiRequest)(endpoint); > return response.json(); >@@ -933,21 +919,22 @@ > return data.failed; > } > >+ if (Object.keys(data.availability_hits).length === 0){ >+ return ill_populate_waiting; >+ } >+ > let str = ''; > let has_some = false; >- if(typeof data.av_hits !== 'undefined' && data.av_hits.length>0){ >- data.av_hits.forEach((av_hit) => { >- if(!av_hit.empty){ >- has_some = true; >- str += '<li><a target="_blank" href="' + av_hit.url + '">' + av_hit.name + '</a></li>' >- } >- }); >- >- if(!has_some){ >- str = ill_batch_none; >+ for (i = 0; i < data.availability_hits.length; i++) { >+ if (!data.availability_hits[i].empty){ >+ has_some = true; >+ str += "<li><a href=" + data.availability_hits[i].url + ">" + data.availability_hits[i].name + "</a></li>" > } >+ } >+ if(!has_some){ >+ str = ill_batch_none; > } >- return str || ill_populate_waiting; >+ return str; > }; > > function buildTable(identifiers) { >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34282
:
153494
|
153564
|
154304
|
154308
|
156385
|
159894