Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 483 #495

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/core/clients/opencga/opencga-parent-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
51 changes: 26 additions & 25 deletions src/core/clients/rest-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -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) {

Expand Down Expand Up @@ -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
}
}

});
}
Expand Down
10 changes: 5 additions & 5 deletions src/webcomponents/file/file-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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"};
Expand All @@ -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();
Expand Down