Merge branch 'sh-fix-double-xhr-pipelines' into 'master'
Remove duplicate XHR request when requesting new pipeline page Closes #58095 See merge request gitlab-org/gitlab-ce!25506
This commit is contained in:
commit
1c30b12b86
|
@ -63,6 +63,10 @@ export default class Poll {
|
|||
const headers = normalizeHeaders(response.headers);
|
||||
const pollInterval = parseInt(headers[this.intervalHeader], 10);
|
||||
if (pollInterval > 0 && successCodes.indexOf(response.status) !== -1 && this.canPoll) {
|
||||
if (this.timeoutID) {
|
||||
clearTimeout(this.timeoutID);
|
||||
}
|
||||
|
||||
this.timeoutID = setTimeout(() => {
|
||||
this.makeRequest();
|
||||
}, pollInterval);
|
||||
|
@ -101,15 +105,25 @@ export default class Poll {
|
|||
}
|
||||
|
||||
/**
|
||||
* Restarts polling after it has been stoped
|
||||
* Enables polling after it has been stopped
|
||||
*/
|
||||
restart(options) {
|
||||
// update data
|
||||
enable(options) {
|
||||
if (options && options.data) {
|
||||
this.options.data = options.data;
|
||||
}
|
||||
|
||||
this.canPoll = true;
|
||||
|
||||
if (options && options.response) {
|
||||
this.checkConditions(options.response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts polling after it has been stopped and makes a request
|
||||
*/
|
||||
restart(options) {
|
||||
this.enable(options);
|
||||
this.makeRequest();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,8 +94,7 @@ export default {
|
|||
this.isLoading = false;
|
||||
this.successCallback(response);
|
||||
|
||||
// restart polling
|
||||
this.poll.restart({ data: this.requestData });
|
||||
this.poll.enable({ data: this.requestData, response });
|
||||
})
|
||||
.catch(() => {
|
||||
this.isLoading = false;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Remove duplicate XHR request when requesting new pipeline page
|
||||
merge_request: 25506
|
||||
author:
|
||||
type: fixed
|
|
@ -153,6 +153,36 @@ describe('Poll', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('enable', () => {
|
||||
it('should enable polling upon a response', done => {
|
||||
jasmine.clock().install();
|
||||
|
||||
const Polling = new Poll({
|
||||
resource: service,
|
||||
method: 'fetch',
|
||||
data: { page: 1 },
|
||||
successCallback: () => {},
|
||||
});
|
||||
|
||||
Polling.enable({
|
||||
data: { page: 4 },
|
||||
response: { status: 200, headers: { 'poll-interval': 1 } },
|
||||
});
|
||||
|
||||
jasmine.clock().tick(1);
|
||||
jasmine.clock().uninstall();
|
||||
|
||||
waitForAllCallsToFinish(service, 1, () => {
|
||||
Polling.stop();
|
||||
|
||||
expect(service.fetch.calls.count()).toEqual(1);
|
||||
expect(service.fetch).toHaveBeenCalledWith({ page: 4 });
|
||||
expect(Polling.options.data).toEqual({ page: 4 });
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('restart', () => {
|
||||
it('should restart polling when its called', done => {
|
||||
mockServiceCall(service, { status: 200, headers: { 'poll-interval': 1 } });
|
||||
|
@ -171,6 +201,7 @@ describe('Poll', () => {
|
|||
});
|
||||
|
||||
spyOn(Polling, 'stop').and.callThrough();
|
||||
spyOn(Polling, 'enable').and.callThrough();
|
||||
spyOn(Polling, 'restart').and.callThrough();
|
||||
|
||||
Polling.makeRequest();
|
||||
|
@ -181,6 +212,7 @@ describe('Poll', () => {
|
|||
expect(service.fetch.calls.count()).toEqual(2);
|
||||
expect(service.fetch).toHaveBeenCalledWith({ page: 4 });
|
||||
expect(Polling.stop).toHaveBeenCalled();
|
||||
expect(Polling.enable).toHaveBeenCalled();
|
||||
expect(Polling.restart).toHaveBeenCalled();
|
||||
expect(Polling.options.data).toEqual({ page: 4 });
|
||||
done();
|
||||
|
|
Loading…
Reference in New Issue