diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-04 09:09:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-04 09:09:34 +0300 |
commit | a2f16969fa9bb982d5ec01f18efff5eabfc89a67 (patch) | |
tree | 881f7d8db86c1758fd21c070908a26b3d1d032c8 /app/assets/javascripts/diffs | |
parent | edf27428120b9726e34e577e5b1d3371c74baf1d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/diffs')
-rw-r--r-- | app/assets/javascripts/diffs/components/app.vue | 1 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/actions.js | 32 |
2 files changed, 29 insertions, 4 deletions
diff --git a/app/assets/javascripts/diffs/components/app.vue b/app/assets/javascripts/diffs/components/app.vue index 53eb8cd8eb8..731050f2e51 100644 --- a/app/assets/javascripts/diffs/components/app.vue +++ b/app/assets/javascripts/diffs/components/app.vue @@ -539,6 +539,7 @@ export default { <template #total>{{ diffFiles.length }}</template> </gl-sprintf> </div> + <gl-loading-icon v-else-if="retrievingBatches" size="lg" /> </template> <no-changes v-else :changes-empty-state-illustration="changesEmptyStateIllustration" /> </div> diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js index 51d9fe12102..c41828a4221 100644 --- a/app/assets/javascripts/diffs/store/actions.js +++ b/app/assets/javascripts/diffs/store/actions.js @@ -75,22 +75,33 @@ export const setBaseConfig = ({ commit }, options) => { }; export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { + const diffsGradualLoad = window.gon?.features?.diffsGradualLoad; + let perPage = DIFFS_PER_PAGE; + let increaseAmount = 1.4; + + if (diffsGradualLoad) { + perPage = state.viewDiffsFileByFile ? 1 : 5; + } + + const startPage = diffsGradualLoad ? 0 : 1; const id = window?.location?.hash; const isNoteLink = id.indexOf('#note') === 0; const urlParams = { - per_page: DIFFS_PER_PAGE, w: state.showWhitespace ? '0' : '1', view: 'inline', }; + let totalLoaded = 0; commit(types.SET_BATCH_LOADING, true); commit(types.SET_RETRIEVING_BATCHES, true); eventHub.$emit(EVT_PERF_MARK_DIFF_FILES_START); - const getBatch = (page = 1) => + const getBatch = (page = startPage) => axios - .get(mergeUrlParams({ ...urlParams, page }, state.endpointBatch)) + .get(mergeUrlParams({ ...urlParams, page, per_page: perPage }, state.endpointBatch)) .then(({ data: { pagination, diff_files } }) => { + totalLoaded += diff_files.length; + commit(types.SET_DIFF_DATA_BATCH, { diff_files }); commit(types.SET_BATCH_LOADING, false); @@ -102,7 +113,10 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { dispatch('setCurrentDiffFileIdFromNote', id.split('_').pop()); } - if (!pagination.next_page) { + if ( + (diffsGradualLoad && totalLoaded === pagination.total_pages) || + (!diffsGradualLoad && !pagination.next_page) + ) { commit(types.SET_RETRIEVING_BATCHES, false); // We need to check that the currentDiffFileId points to a file that exists @@ -128,6 +142,16 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { }), ); } + + return null; + } + + if (diffsGradualLoad) { + const nextPage = page + perPage; + perPage = Math.min(Math.ceil(perPage * increaseAmount), 30); + increaseAmount = Math.min(increaseAmount + 0.2, 2); + + return nextPage; } return pagination.next_page; |