Skip to content

Commit

Permalink
Make it so no duplicate AJAX requests are sent
Browse files Browse the repository at this point in the history
Not sure if there are race conditions
  • Loading branch information
xiaohutai committed Oct 9, 2023
1 parent d72bfed commit 662b1df
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions assets/js/app/editor/Components/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,28 @@ export default {
*/
if (this.fetchurl) {
window.selectCache = window.selectCache || {};
window.requestCache = window.requestCache || {};
if (window.selectCache[this.fetchurl]) {
this.options = window.selectCache[this.fetchurl];
fixSelectedItems.call(this);
} else {
this.isLoading = true;
$.ajax({ url: this.fetchurl, dataType: 'json', cache: true }).then(response => {
} else if (window.requestCache[this.fetchurl]) {
window.requestCache[this.fetchurl].then(response => {
this.options = response;
window.selectCache[this.fetchurl] = response;
this.isLoading = false;
fixSelectedItems.call(this);
});
} else {
this.isLoading = true;
window.requestCache[this.fetchurl] = $.ajax({ url: this.fetchurl, dataType: 'json', cache: true });
window.requestCache[this.fetchurl].then(
response => {
this.options = response;
window.selectCache[this.fetchurl] = response;
this.isLoading = false;
fixSelectedItems.call(this);
},
);
}
} else {
fixSelectedItems.call(this);
Expand Down

0 comments on commit 662b1df

Please sign in to comment.