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

Performance Issue: Unnecessary GET request for deleting frames #9

Closed
arnabsen1729 opened this issue Jan 2, 2021 · 1 comment
Closed
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@arnabsen1729
Copy link
Collaborator

Description

function deleteframe(frameid) {
if (confirm("Delete this Frame?")) {
loader('show');
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 201) {
loader('hide');
getframes();
}
};
xhttp.open("DELETE", "https://api.iwasat.events/api/v1/frames?id=" + frameid, true);
xhttp.onerror = function () {
loader('hide');
alertpopup("Unexpected Error!", 'open');
};
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader("Authorization", `Bearer ${sessionStorage.getItem('token')}`);
xhttp.send();
}
}

When a user heads over to gallery.html and then deletes an image, two requests happen one DELETE and another GET (line number 169) . Now the GET request is very time-consuming, so we should try to make fewer GET requests.

Solution

When the user first loads the gallery.html, we make one GET request and store the data we get in an array. Each element of an array represent one frame. For deletion, we can simply make the DELETE request and remove the corresponding frame from the array, and also toggle the display of that frame. This will make sure that there is one GET request in that user session.

@arnabsen1729 arnabsen1729 added enhancement New feature or request good first issue Good for newcomers labels Jan 2, 2021
@rajinderpalsingh2001 rajinderpalsingh2001 self-assigned this Jan 3, 2021
@rajinderpalsingh2001
Copy link
Collaborator

Previously:

gallery.html loads ---> getframes() called with GET request for Getting Frames
if (user deletes frame ){
deleteframe() called
getframes() again called for fetching again frames
}

Now:

gallery.html loads ---> getframes() called with GET request for Getting Frames --->all frames stored in array ---> displayarrayofframes() called for displaying fetched array

if (user deletes frame ){
deleteframe() called
delete that frame from array
displayarrayofframes() called
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants