Commit 6f8463e4 authored by Alexander Turinske's avatar Alexander Turinske

Set `assumeImmutableResults` in security dashboard

- update apollo client to `assumeImmutableResults` to increase
  performance
- update `updateQuery` for project/group/instane-level security
  dashboard to be consistent and immutable
parent f91ea8e2
<script> <script>
import produce from 'immer';
import { GlAlert, GlButton, GlIntersectionObserver } from '@gitlab/ui'; import { GlAlert, GlButton, GlIntersectionObserver } from '@gitlab/ui';
import VulnerabilityList from './vulnerability_list.vue'; import VulnerabilityList from './vulnerability_list.vue';
import vulnerabilitiesQuery from '../graphql/group_vulnerabilities.graphql'; import vulnerabilitiesQuery from '../graphql/group_vulnerabilities.graphql';
...@@ -66,10 +67,14 @@ export default { ...@@ -66,10 +67,14 @@ export default {
this.$apollo.queries.vulnerabilities.fetchMore({ this.$apollo.queries.vulnerabilities.fetchMore({
variables: { after: this.pageInfo.endCursor }, variables: { after: this.pageInfo.endCursor },
updateQuery: (previousResult, { fetchMoreResult }) => { updateQuery: (previousResult, { fetchMoreResult }) => {
fetchMoreResult.group.vulnerabilities.nodes.unshift( const results = produce(fetchMoreResult, draftData => {
// eslint-disable-next-line no-param-reassign
draftData.group.vulnerabilities.nodes = [
...previousResult.group.vulnerabilities.nodes, ...previousResult.group.vulnerabilities.nodes,
); ...draftData.group.vulnerabilities.nodes,
return fetchMoreResult; ];
});
return results;
}, },
}); });
} }
......
<script> <script>
import produce from 'immer';
import { GlAlert, GlButton, GlIntersectionObserver, GlLoadingIcon } from '@gitlab/ui'; import { GlAlert, GlButton, GlIntersectionObserver, GlLoadingIcon } from '@gitlab/ui';
import { fetchPolicies } from '~/lib/graphql'; import { fetchPolicies } from '~/lib/graphql';
import VulnerabilityList from './vulnerability_list.vue'; import VulnerabilityList from './vulnerability_list.vue';
...@@ -63,8 +64,14 @@ export default { ...@@ -63,8 +64,14 @@ export default {
this.$apollo.queries.vulnerabilities.fetchMore({ this.$apollo.queries.vulnerabilities.fetchMore({
variables: { after: this.pageInfo.endCursor }, variables: { after: this.pageInfo.endCursor },
updateQuery: (previousResult, { fetchMoreResult }) => { updateQuery: (previousResult, { fetchMoreResult }) => {
fetchMoreResult.vulnerabilities.nodes.unshift(...previousResult.vulnerabilities.nodes); const results = produce(fetchMoreResult, draftData => {
return fetchMoreResult; // eslint-disable-next-line no-param-reassign
draftData.vulnerabilities.nodes = [
...previousResult.vulnerabilities.nodes,
...draftData.vulnerabilities.nodes,
];
});
return results;
}, },
}); });
} }
......
<script> <script>
import produce from 'immer';
import { GlAlert, GlButton, GlIntersectionObserver } from '@gitlab/ui'; import { GlAlert, GlButton, GlIntersectionObserver } from '@gitlab/ui';
import { __ } from '~/locale'; import { __ } from '~/locale';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
...@@ -93,12 +94,14 @@ export default { ...@@ -93,12 +94,14 @@ export default {
this.$apollo.queries.vulnerabilities.fetchMore({ this.$apollo.queries.vulnerabilities.fetchMore({
variables: { after: this.pageInfo.endCursor }, variables: { after: this.pageInfo.endCursor },
updateQuery: (previousResult, { fetchMoreResult }) => { updateQuery: (previousResult, { fetchMoreResult }) => {
const newResult = { ...fetchMoreResult }; const results = produce(fetchMoreResult, draftData => {
previousResult.project.vulnerabilities.nodes.push( // eslint-disable-next-line no-param-reassign
...fetchMoreResult.project.vulnerabilities.nodes, draftData.project.vulnerabilities.nodes = [
); ...previousResult.project.vulnerabilities.nodes,
newResult.project.vulnerabilities.nodes = previousResult.project.vulnerabilities.nodes; ...draftData.project.vulnerabilities.nodes,
return newResult; ];
});
return results;
}, },
}); });
} }
......
...@@ -18,6 +18,7 @@ const defaultClient = createDefaultClient( ...@@ -18,6 +18,7 @@ const defaultClient = createDefaultClient(
cacheConfig: { cacheConfig: {
fragmentMatcher, fragmentMatcher,
}, },
assumeImmutableResults: true,
}, },
); );
......
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