Skip to content

Commit 6ee9176

Browse files
John-Weakwidatama
authored andcommitted
[fix] return same promise if multiple calls are made instead of aborting duplicate request
1 parent 54a280d commit 6ee9176

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

frontend/express/public/javascripts/countly/countly.event.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
_period = null;
1818
var _activeLoadedEvent = "";
1919
var _activeLoadedSegmentation = "";
20+
var _refreshEventsPromise = null;
2021

2122
countlyEvent.hasLoadedData = function() {
2223
if (_activeLoadedEvent && _activeLoadedEvent === _activeEvent && _activeLoadedSegmentation === _activeSegmentation) {
@@ -497,7 +498,11 @@
497498

498499
countlyEvent.refreshEvents = function() {
499500
if (!countlyCommon.DEBUG) {
500-
return $.ajax({
501+
if (_refreshEventsPromise) {
502+
return _refreshEventsPromise;
503+
}
504+
505+
_refreshEventsPromise = $.ajax({
501506
type: "GET",
502507
url: countlyCommon.API_PARTS.data.r,
503508
data: {
@@ -510,8 +515,13 @@
510515
if (!_activeEvent && countlyEvent.getEvents()[0]) {
511516
_activeEvent = countlyEvent.getEvents()[0].key;
512517
}
518+
},
519+
complete: function() {
520+
_refreshEventsPromise = null;
513521
}
514522
});
523+
524+
return _refreshEventsPromise;
515525
}
516526
else {
517527
_activeEvents = {};

0 commit comments

Comments
 (0)