Skip to content

Commit

Permalink
Backport PR #6651
Browse files Browse the repository at this point in the history
---------

**Commit 1:**
[courier/segmentedRequest] mark the request "started" synchronously

* Original sha: 8a49926
* Authored by spalger <[email protected]> on 2016-03-24T21:35:00Z

**Commit 2:**
[courier/fetch] detect aborted requests more agressively

* Original sha: c12f18d
* Authored by spalger <[email protected]> on 2016-03-24T21:35:46Z

**Commit 3:**
[courier/callClient] if there are no executable requests, do nothing

* Original sha: 8fef03b
* Authored by spalger <[email protected]> on 2016-03-24T21:36:18Z

**Commit 4:**
[courier/tests] updated test

* Original sha: 985f997
* Authored by spalger <[email protected]> on 2016-03-24T22:25:31Z
  • Loading branch information
elastic-jasper committed Mar 28, 2016
1 parent 7a5a7ac commit 7fe9e9c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/ui/public/courier/fetch/_call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ define(function (require) {
var executable = statuses.filter(isRequest);
var execCount = executable.length;

if (!execCount) return Promise.resolve([]);

// resolved by respond()
var esPromise;
var defer = Promise.defer();
Expand Down
12 changes: 8 additions & 4 deletions src/ui/public/courier/fetch/_fetch_these.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ define(function (require) {
}

function fetchWithStrategy(strategy, requests) {
function replaceAbortedRequests() {
requests = requests.map(r => r.aborted ? ABORTED : r);
}

requests = requests.map(function (req) {
return req.aborted ? ABORTED : req;
});

replaceAbortedRequests();
return startRequests(requests)
.then(function () {
replaceAbortedRequests();
return callClient(strategy, requests);
})
.then(function (responses) {
replaceAbortedRequests();
return callResponseHandlers(requests, responses);
})
.then(function (responses) {
replaceAbortedRequests();
return continueIncomplete(strategy, requests, responses, fetchWithStrategy);
})
.then(function (responses) {
replaceAbortedRequests();
return responses.map(function (resp) {
switch (resp) {
case ABORTED:
Expand Down
4 changes: 1 addition & 3 deletions src/ui/public/courier/fetch/request/__tests__/segmented.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ describe('ui/courier/fetch/request/segmented', () => {
expect(returned.then).to.be.Function;
});

it('does not call super.start() until promise is resolved', () => {
expect(searchReqStart.called).to.be(false);
$rootScope.$apply();
it('calls super.start() synchronously', () => {
expect(searchReqStart.called).to.be(true);
});
});
Expand Down
6 changes: 4 additions & 2 deletions src/ui/public/courier/fetch/request/segmented.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ define(function (require) {
SegmentedReq.prototype.start = function () {
var self = this;

SearchReq.prototype.start.call(this);

this._complete = [];
this._active = null;
this._segments = [];
Expand All @@ -58,12 +60,12 @@ define(function (require) {
// parameters via the handle
if (_.isFunction(this._initFn)) this._initFn(this._handle);
return this._createQueue().then(function (queue) {
if (self.stopped) return;

self._all = queue.slice(0);

// Send the initial fetch status
self._reportStatus();

return SearchReq.prototype.start.call(self);
});
};

Expand Down

0 comments on commit 7fe9e9c

Please sign in to comment.