Commit b37b804c authored by jerasmus's avatar jerasmus

Preload blobs in repo view

Preloaded the blobs using the hoverLoad directive.

Changelog: performance
parent 15243640
...@@ -7,13 +7,17 @@ import { ...@@ -7,13 +7,17 @@ import {
GlTooltipDirective, GlTooltipDirective,
GlLoadingIcon, GlLoadingIcon,
GlIcon, GlIcon,
GlHoverLoadDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { escapeRegExp } from 'lodash'; import { escapeRegExp } from 'lodash';
import filesQuery from 'shared_queries/repository/files.query.graphql';
import { escapeFileUrl } from '~/lib/utils/url_utility'; import { escapeFileUrl } from '~/lib/utils/url_utility';
import { TREE_PAGE_SIZE } from '~/repository/constants';
import FileIcon from '~/vue_shared/components/file_icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import getRefMixin from '../../mixins/get_ref'; import getRefMixin from '../../mixins/get_ref';
import blobInfoQuery from '../../queries/blob_info.query.graphql';
import commitQuery from '../../queries/commit.query.graphql'; import commitQuery from '../../queries/commit.query.graphql';
export default { export default {
...@@ -28,6 +32,7 @@ export default { ...@@ -28,6 +32,7 @@ export default {
}, },
directives: { directives: {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
GlHoverLoad: GlHoverLoadDirective,
}, },
apollo: { apollo: {
commit: { commit: {
...@@ -139,6 +144,33 @@ export default { ...@@ -139,6 +144,33 @@ export default {
return this.commit && this.commit.lockLabel; return this.commit && this.commit.lockLabel;
}, },
}, },
methods: {
handlePreload() {
return this.isFolder ? this.loadFolder() : this.loadBlob();
},
loadFolder() {
this.apolloQuery(filesQuery, {
projectPath: this.projectPath,
ref: this.ref,
path: this.path,
nextPageCursor: '',
pageSize: TREE_PAGE_SIZE,
});
},
loadBlob() {
if (!this.refactorBlobViewerEnabled) {
return;
}
this.apolloQuery(blobInfoQuery, {
projectPath: this.projectPath,
filePath: this.path,
});
},
apolloQuery(query, variables) {
this.$apollo.query({ query, variables });
},
},
}; };
</script> </script>
...@@ -148,6 +180,7 @@ export default { ...@@ -148,6 +180,7 @@ export default {
<component <component
:is="linkComponent" :is="linkComponent"
ref="link" ref="link"
v-gl-hover-load="handlePreload"
:to="routerLinkTo" :to="routerLinkTo"
:href="url" :href="url"
:class="{ :class="{
......
query getBlobInfo($projectPath: ID!, $filePath: String!) { query getBlobInfo($projectPath: ID!, $filePath: String!) {
project(fullPath: $projectPath) { project(fullPath: $projectPath) {
id
repository { repository {
blobs(paths: [$filePath]) { blobs(paths: [$filePath]) {
nodes { nodes {
......
import { GlBadge, GlLink, GlIcon } from '@gitlab/ui'; import { GlBadge, GlLink, GlIcon } from '@gitlab/ui';
import { shallowMount, RouterLinkStub } from '@vue/test-utils'; import { shallowMount, RouterLinkStub } from '@vue/test-utils';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import TableRow from '~/repository/components/table/row.vue'; import TableRow from '~/repository/components/table/row.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
import { FILE_SYMLINK_MODE } from '~/vue_shared/constants'; import { FILE_SYMLINK_MODE } from '~/vue_shared/constants';
...@@ -19,6 +20,9 @@ function factory(propsData = {}) { ...@@ -19,6 +20,9 @@ function factory(propsData = {}) {
projectPath: 'gitlab-org/gitlab-ce', projectPath: 'gitlab-org/gitlab-ce',
url: `https://test.com`, url: `https://test.com`,
}, },
directives: {
GlHoverLoad: createMockDirective(),
},
provide: { provide: {
glFeatures: { refactorBlobViewer: true }, glFeatures: { refactorBlobViewer: true },
}, },
...@@ -34,6 +38,8 @@ function factory(propsData = {}) { ...@@ -34,6 +38,8 @@ function factory(propsData = {}) {
} }
describe('Repository table row component', () => { describe('Repository table row component', () => {
const findRouterLink = () => vm.find(RouterLinkStub);
afterEach(() => { afterEach(() => {
vm.destroy(); vm.destroy();
}); });
...@@ -81,6 +87,21 @@ describe('Repository table row component', () => { ...@@ -81,6 +87,21 @@ describe('Repository table row component', () => {
}); });
}); });
it('renders a gl-hover-load directive', () => {
factory({
id: '1',
sha: '123',
path: 'test',
type: 'blob',
currentPath: '/',
});
const hoverLoadDirective = getBinding(findRouterLink().element, 'gl-hover-load');
expect(hoverLoadDirective).not.toBeUndefined();
expect(hoverLoadDirective.value).toBeInstanceOf(Function);
});
it.each` it.each`
type | component | componentName type | component | componentName
${'tree'} | ${RouterLinkStub} | ${'RouterLink'} ${'tree'} | ${RouterLinkStub} | ${'RouterLink'}
......
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