diff --git a/src/core/clients/opencga/opencga-parent-class.js b/src/core/clients/opencga/opencga-parent-class.js index ade9e97c01..437a6d19c8 100644 --- a/src/core/clients/opencga/opencga-parent-class.js +++ b/src/core/clients/opencga/opencga-parent-class.js @@ -168,9 +168,8 @@ export default class OpenCGAParentClass { } generateKey(params) { - // return `${new Error().stack.split("\n at ").slice(0, 5).join("|")}${params?.study}`; - // Josemi 2022-01-28 NOTE: Temporally disable key generation, see issue https://github.com/opencb/jsorolla/issues/380 - return ""; + // if concurrent=true the request bypass the request queue in RestClient + return params?.concurrent !== true ? `${new Error().stack.split("\n at ").slice(0, 5).join("|")}${params?.study}` : false; } } diff --git a/src/core/clients/rest-client.js b/src/core/clients/rest-client.js index a67ae137d2..80e2017055 100644 --- a/src/core/clients/rest-client.js +++ b/src/core/clients/rest-client.js @@ -69,7 +69,10 @@ export class RestClient { call(url, options, k) { let method = "GET"; let async = true; - // const key = RestClient.hash(k || "RandomString"); + + // k is false iff there is concurrent=true param in the call + const key = k ? RestClient.hash(k) : null; + let dataResponse = null; const eventFire = new CustomEvent("request", { @@ -93,26 +96,25 @@ export class RestClient { // Creating the promise return new Promise((resolve, reject) => { - // let key = `${new Error().stack.split("\n at ").slice(0,6).join("|")}`; const request = new XMLHttpRequest(); - // Josemi 2022-01-28 NOTE: disabled requests registry until due to issues with images until we found a better solution - // Related issue: https://github.com/opencb/jsorolla/issues/380 - // if (this.requests[key]) { - // // pending prev request - // this.requests[key] = {...this.requests[key], pending: true}; - - // } else { - // // pending false as there is no prev request - // this.requests[key] = {pending: false, request, url, key}; - // } + // k is false iff there is concurrent=true param in the call + if (key) { + if (this.requests[key]) { + // pending prev request + this.requests[key] = {...this.requests[key], pending: true}; + } else { + // pending false as there is no prev request + this.requests[key] = {pending: false, request, url, key}; + } + } request.onload = event => { // console.log("on load EVENT", event); // console.log("on load URL", url); // request is fulfilled - // delete this.requests[key]; + delete this.requests[key]; if (request.status === 200) { @@ -199,18 +201,17 @@ export class RestClient { request.send(); } - // if (this.requests[key]) { - // // console.log("FULL LIST", Object.entries(this.requests)) - // // console.log("this.requests[key]", this.requests[key]); - - // if (this.requests[key].pending) { - // console.warn("aborting request", this.requests[key].url); - // this.requests[key].request.abort(); - // delete this.requests[key]; - // } else { - // // not aborting - // } - // } + if (this.requests[key]) { + // console.log("FULL LIST", Object.entries(this.requests)) + // console.log("this.requests[key]", this.requests[key]); + if (this.requests[key].pending) { + console.warn("aborting request", this.requests[key].url); + this.requests[key].request.abort(); + delete this.requests[key]; + } else { + // not aborting + } + } }); } diff --git a/src/webcomponents/file/file-preview.js b/src/webcomponents/file/file-preview.js index ff37e65ef7..b50b61a15d 100644 --- a/src/webcomponents/file/file-preview.js +++ b/src/webcomponents/file/file-preview.js @@ -98,7 +98,7 @@ export default class FilePreview extends LitElement { fileIdsObserver() { if (this.opencgaSession && this.fileIds) { - this.opencgaSession.opencgaClient.files().info(this.fileIds.map(fileId => fileId.replaceAll("/", ":")).join(","), {study: this.opencgaSession.study.fqn}) + this.opencgaSession.opencgaClient.files().info(this.fileIds.map(fileId => fileId.replaceAll("/", ":")).join(","), {study: this.opencgaSession.study.fqn, concurrent: true}) .then(response => { this.files = response.responses[0].results; }) @@ -132,7 +132,7 @@ export default class FilePreview extends LitElement { case "UNKNOWN": case "TAB_SEPARATED_VALUES": fileWithContent.contentType = "text"; - this.opencgaSession.opencgaClient.files().head(fileWithContent.id, params) + this.opencgaSession.opencgaClient.files().head(fileWithContent.id, {...params, concurrent: true}) .then(response => { const {format, content} = response.getResult(0); this.format = format; @@ -147,7 +147,7 @@ export default class FilePreview extends LitElement { break; case "JSON": fileWithContent.contentType = "json"; - this.opencgaSession.opencgaClient.files().head(fileWithContent.id, params) + this.opencgaSession.opencgaClient.files().head(fileWithContent.id, {...params, concurrent: true}) .then(response => { const {content} = response.getResult(0); try { @@ -165,7 +165,7 @@ export default class FilePreview extends LitElement { break; case "BAM": fileWithContent.contentType = "json"; - this.opencgaSession.opencgaClient.files().info(fileWithContent.id, {study: this.opencgaSession.study.fqn}) + this.opencgaSession.opencgaClient.files().info(fileWithContent.id, {study: this.opencgaSession.study.fqn, concurrent: true}) .then(response => { const {attributes} = response.getResult(0); fileWithContent.content = attributes?.alignmentHeader ?? {content: "No content"}; @@ -174,7 +174,7 @@ export default class FilePreview extends LitElement { break; case "IMAGE": fileWithContent.contentType = "image"; - this.opencgaSession.opencgaClient.files().image(fileWithContent.id, {study: this.opencgaSession.study.fqn}) + this.opencgaSession.opencgaClient.files().image(fileWithContent.id, {study: this.opencgaSession.study.fqn, concurrent: true}) .then(response => { fileWithContent.content = response.responses[0].results[0].content; this.requestUpdate();