Commit e84cf8ce authored by Phil Hughes's avatar Phil Hughes

Merge branch '214685-prevent-fetching-commits-for-next-page' into 'master'

Prevent fetching commits for files that are not on the current page

See merge request gitlab-org/gitlab!63525
parents 8a185ce3 ce8bba14
...@@ -51,6 +51,9 @@ export default { ...@@ -51,6 +51,9 @@ export default {
}; };
}, },
computed: { computed: {
totalEntries() {
return Object.values(this.entries).flat().length;
},
tableCaption() { tableCaption() {
if (this.isLoading) { if (this.isLoading) {
return sprintf( return sprintf(
...@@ -111,6 +114,7 @@ export default { ...@@ -111,6 +114,7 @@ export default {
:submodule-tree-url="entry.treeUrl" :submodule-tree-url="entry.treeUrl"
:lfs-oid="entry.lfsOid" :lfs-oid="entry.lfsOid"
:loading-path="loadingPath" :loading-path="loadingPath"
:total-entries="totalEntries"
/> />
</template> </template>
<template v-if="isLoading"> <template v-if="isLoading">
......
...@@ -43,12 +43,17 @@ export default { ...@@ -43,12 +43,17 @@ export default {
type: this.type, type: this.type,
path: this.currentPath, path: this.currentPath,
projectPath: this.projectPath, projectPath: this.projectPath,
maxOffset: this.totalEntries,
}; };
}, },
}, },
}, },
mixins: [getRefMixin, glFeatureFlagMixin()], mixins: [getRefMixin, glFeatureFlagMixin()],
props: { props: {
totalEntries: {
type: Number,
required: true,
},
id: { id: {
type: String, type: String,
required: true, required: true,
......
...@@ -17,15 +17,21 @@ const fragmentMatcher = new IntrospectionFragmentMatcher({ ...@@ -17,15 +17,21 @@ const fragmentMatcher = new IntrospectionFragmentMatcher({
const defaultClient = createDefaultClient( const defaultClient = createDefaultClient(
{ {
Query: { Query: {
commit(_, { path, fileName, type }) { commit(_, { path, fileName, type, maxOffset }) {
return new Promise((resolve) => { return new Promise((resolve) => {
fetchLogsTree(defaultClient, path, '0', { fetchLogsTree(
resolve, defaultClient,
entry: { path,
name: fileName, '0',
type, {
resolve,
entry: {
name: fileName,
type,
},
}, },
}); maxOffset,
);
}); });
}, },
readme(_, { url }) { readme(_, { url }) {
......
...@@ -7,6 +7,7 @@ import refQuery from './queries/ref.query.graphql'; ...@@ -7,6 +7,7 @@ import refQuery from './queries/ref.query.graphql';
const fetchpromises = {}; const fetchpromises = {};
const resolvers = {}; const resolvers = {};
let maxOffset;
export function resolveCommit(commits, path, { resolve, entry }) { export function resolveCommit(commits, path, { resolve, entry }) {
const commit = commits.find( const commit = commits.find(
...@@ -18,7 +19,15 @@ export function resolveCommit(commits, path, { resolve, entry }) { ...@@ -18,7 +19,15 @@ export function resolveCommit(commits, path, { resolve, entry }) {
} }
} }
export function fetchLogsTree(client, path, offset, resolver = null) { export function fetchLogsTree(client, path, offset, resolver = null, _maxOffset = null) {
if (_maxOffset) {
maxOffset = _maxOffset;
}
if (Number(offset) > maxOffset) {
return Promise.resolve();
}
if (resolver) { if (resolver) {
if (!resolvers[path]) { if (!resolvers[path]) {
resolvers[path] = [resolver]; resolvers[path] = [resolver];
...@@ -60,6 +69,7 @@ export function fetchLogsTree(client, path, offset, resolver = null) { ...@@ -60,6 +69,7 @@ export function fetchLogsTree(client, path, offset, resolver = null) {
fetchLogsTree(client, path, headerLogsOffset); fetchLogsTree(client, path, headerLogsOffset);
} else { } else {
delete resolvers[path]; delete resolvers[path];
maxOffset = null;
} }
}); });
......
#import "ee_else_ce/repository/queries/commit.fragment.graphql" #import "ee_else_ce/repository/queries/commit.fragment.graphql"
query getCommit($fileName: String!, $type: String!, $path: String!) { query getCommit($fileName: String!, $type: String!, $path: String!, $maxOffset: Number!) {
commit(path: $path, fileName: $fileName, type: $type) @client { commit(path: $path, fileName: $fileName, type: $type, maxOffset: $maxOffset) @client {
...TreeEntryCommit ...TreeEntryCommit
} }
} }
...@@ -19,6 +19,7 @@ function factory(propsData = {}) { ...@@ -19,6 +19,7 @@ function factory(propsData = {}) {
name: propsData.path, name: propsData.path,
projectPath: 'gitlab-org/gitlab-ce', projectPath: 'gitlab-org/gitlab-ce',
url: `https://test.com`, url: `https://test.com`,
totalEntries: 10,
}, },
directives: { directives: {
GlHoverLoad: createMockDirective(), GlHoverLoad: createMockDirective(),
......
...@@ -69,6 +69,11 @@ describe('fetchLogsTree', () => { ...@@ -69,6 +69,11 @@ describe('fetchLogsTree', () => {
mock.restore(); mock.restore();
}); });
it('does not call axios get if offset is larger than the maximum offset', () =>
fetchLogsTree(client, '', '1000', resolver, 900).then(() => {
expect(axios.get).not.toHaveBeenCalled();
}));
it('calls axios get', () => it('calls axios get', () =>
fetchLogsTree(client, '', '0', resolver).then(() => { fetchLogsTree(client, '', '0', resolver).then(() => {
expect(axios.get).toHaveBeenCalledWith('/gitlab-org/gitlab-foss/-/refs/main/logs_tree/', { expect(axios.get).toHaveBeenCalledWith('/gitlab-org/gitlab-foss/-/refs/main/logs_tree/', {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment