Merge "Prefetch /diff requests when expanding all diffs"
This commit is contained in:
@@ -1279,6 +1279,14 @@ class GrFileList extends mixinBehaviors( [
|
|||||||
_renderInOrder(files, diffElements, initialCount) {
|
_renderInOrder(files, diffElements, initialCount) {
|
||||||
let iter = 0;
|
let iter = 0;
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const path = file.path;
|
||||||
|
const diffElem = this._findDiffByPath(path, diffElements);
|
||||||
|
if (diffElem) {
|
||||||
|
diffElem.prefetchDiff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (new Promise(resolve => {
|
return (new Promise(resolve => {
|
||||||
this.dispatchEvent(new CustomEvent('reload-drafts', {
|
this.dispatchEvent(new CustomEvent('reload-drafts', {
|
||||||
detail: {resolve},
|
detail: {resolve},
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ suite('gr-file-list tests', () => {
|
|||||||
});
|
});
|
||||||
stub('gr-diff-host', {
|
stub('gr-diff-host', {
|
||||||
reload() { return Promise.resolve(); },
|
reload() { return Promise.resolve(); },
|
||||||
|
prefetchDiff() {},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Element must be wrapped in an element with direct access to the
|
// Element must be wrapped in an element with direct access to the
|
||||||
@@ -1106,6 +1107,7 @@ suite('gr-file-list tests', () => {
|
|||||||
reload() {
|
reload() {
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
|
prefetchDiff() {},
|
||||||
cancel() {},
|
cancel() {},
|
||||||
getCursorStops() { return []; },
|
getCursorStops() { return []; },
|
||||||
addEventListener(eventName, callback) {
|
addEventListener(eventName, callback) {
|
||||||
@@ -1163,6 +1165,7 @@ suite('gr-file-list tests', () => {
|
|||||||
const diffs = [{
|
const diffs = [{
|
||||||
path: 'p0',
|
path: 'p0',
|
||||||
style: {},
|
style: {},
|
||||||
|
prefetchDiff() {},
|
||||||
reload() {
|
reload() {
|
||||||
assert.equal(callCount++, 2);
|
assert.equal(callCount++, 2);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@@ -1170,6 +1173,7 @@ suite('gr-file-list tests', () => {
|
|||||||
}, {
|
}, {
|
||||||
path: 'p1',
|
path: 'p1',
|
||||||
style: {},
|
style: {},
|
||||||
|
prefetchDiff() {},
|
||||||
reload() {
|
reload() {
|
||||||
assert.equal(callCount++, 1);
|
assert.equal(callCount++, 1);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@@ -1177,6 +1181,7 @@ suite('gr-file-list tests', () => {
|
|||||||
}, {
|
}, {
|
||||||
path: 'p2',
|
path: 'p2',
|
||||||
style: {},
|
style: {},
|
||||||
|
prefetchDiff() {},
|
||||||
reload() {
|
reload() {
|
||||||
assert.equal(callCount++, 0);
|
assert.equal(callCount++, 0);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@@ -1199,6 +1204,7 @@ suite('gr-file-list tests', () => {
|
|||||||
const diffs = [{
|
const diffs = [{
|
||||||
path: 'p0',
|
path: 'p0',
|
||||||
style: {},
|
style: {},
|
||||||
|
prefetchDiff() {},
|
||||||
reload() {
|
reload() {
|
||||||
assert.equal(reviewStub.callCount, 2);
|
assert.equal(reviewStub.callCount, 2);
|
||||||
assert.equal(callCount++, 2);
|
assert.equal(callCount++, 2);
|
||||||
@@ -1207,6 +1213,7 @@ suite('gr-file-list tests', () => {
|
|||||||
}, {
|
}, {
|
||||||
path: 'p1',
|
path: 'p1',
|
||||||
style: {},
|
style: {},
|
||||||
|
prefetchDiff() {},
|
||||||
reload() {
|
reload() {
|
||||||
assert.equal(reviewStub.callCount, 1);
|
assert.equal(reviewStub.callCount, 1);
|
||||||
assert.equal(callCount++, 1);
|
assert.equal(callCount++, 1);
|
||||||
@@ -1215,6 +1222,7 @@ suite('gr-file-list tests', () => {
|
|||||||
}, {
|
}, {
|
||||||
path: 'p2',
|
path: 'p2',
|
||||||
style: {},
|
style: {},
|
||||||
|
prefetchDiff() {},
|
||||||
reload() {
|
reload() {
|
||||||
assert.equal(reviewStub.callCount, 0);
|
assert.equal(reviewStub.callCount, 0);
|
||||||
assert.equal(callCount++, 0);
|
assert.equal(callCount++, 0);
|
||||||
@@ -1237,6 +1245,7 @@ suite('gr-file-list tests', () => {
|
|||||||
const diffs = [{
|
const diffs = [{
|
||||||
path: 'p',
|
path: 'p',
|
||||||
style: {},
|
style: {},
|
||||||
|
prefetchDiff() {},
|
||||||
reload() { return Promise.resolve(); },
|
reload() { return Promise.resolve(); },
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@@ -1566,6 +1575,7 @@ suite('gr-file-list tests', () => {
|
|||||||
});
|
});
|
||||||
stub('gr-diff-host', {
|
stub('gr-diff-host', {
|
||||||
reload() { return Promise.resolve(); },
|
reload() { return Promise.resolve(); },
|
||||||
|
prefetchDiff() {},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Element must be wrapped in an element with direct access to the
|
// Element must be wrapped in an element with direct access to the
|
||||||
|
|||||||
@@ -218,6 +218,11 @@ class GrDiffHost extends mixinBehaviors( [
|
|||||||
notify: true,
|
notify: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_fetchDiffPromise: {
|
||||||
|
type: Object,
|
||||||
|
value: null,
|
||||||
|
},
|
||||||
|
|
||||||
/** @type {?Object} */
|
/** @type {?Object} */
|
||||||
_blame: {
|
_blame: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -535,8 +540,21 @@ class GrDiffHost extends mixinBehaviors( [
|
|||||||
!this.noAutoRender;
|
!this.noAutoRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(milutin): Use rest-api with fetchCacheURL instead of this.
|
||||||
|
prefetchDiff() {
|
||||||
|
if (!!this.changeNum && !!this.patchRange && !!this.path
|
||||||
|
&& this._fetchDiffPromise === null) {
|
||||||
|
this._fetchDiffPromise = this._getDiff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @return {!Promise<!Object>} */
|
/** @return {!Promise<!Object>} */
|
||||||
_getDiff() {
|
_getDiff() {
|
||||||
|
if (this._fetchDiffPromise !== null) {
|
||||||
|
const fetchDiffPromise = this._fetchDiffPromise;
|
||||||
|
this._fetchDiffPromise = null;
|
||||||
|
return fetchDiffPromise;
|
||||||
|
}
|
||||||
// Wrap the diff request in a new promise so that the error handler
|
// Wrap the diff request in a new promise so that the error handler
|
||||||
// rejects the promise, allowing the error to be handled in the .catch.
|
// rejects the promise, allowing the error to be handled in the .catch.
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -907,6 +925,7 @@ class GrDiffHost extends mixinBehaviors( [
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._fetchDiffPromise = null;
|
||||||
if (preferredWhitespaceLevel !== loadedWhitespaceLevel &&
|
if (preferredWhitespaceLevel !== loadedWhitespaceLevel &&
|
||||||
!noRenderOnPrefsChange) {
|
!noRenderOnPrefsChange) {
|
||||||
this.reload();
|
this.reload();
|
||||||
|
|||||||
@@ -445,6 +445,19 @@ suite('gr-diff-host tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('prefetch getDiff', done => {
|
||||||
|
const diffRestApiStub = sandbox.stub(element.$.restAPI, 'getDiff')
|
||||||
|
.returns(Promise.resolve({content: []}));
|
||||||
|
element.changeNum = 123;
|
||||||
|
element.patchRange = {basePatchNum: 1, patchNum: 2};
|
||||||
|
element.path = 'file.txt';
|
||||||
|
element.prefetchDiff();
|
||||||
|
element._getDiff().then(() =>{
|
||||||
|
assert.isTrue(diffRestApiStub.calledOnce);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('_getDiff handles null diff responses', done => {
|
test('_getDiff handles null diff responses', done => {
|
||||||
stub('gr-rest-api-interface', {
|
stub('gr-rest-api-interface', {
|
||||||
getDiff() { return Promise.resolve(null); },
|
getDiff() { return Promise.resolve(null); },
|
||||||
|
|||||||
Reference in New Issue
Block a user