Commit c3ac782b authored by mgandres's avatar mgandres

Add etag caching for pipeline status in pipeline editor

We will use etag caching for the pipeline status so we don't have to
send full requests to get the updated pipeline status each time.
parent f9a40430
...@@ -11,6 +11,7 @@ import commitCIFile from '../../graphql/mutations/commit_ci_file.mutation.graphq ...@@ -11,6 +11,7 @@ import commitCIFile from '../../graphql/mutations/commit_ci_file.mutation.graphq
import getCommitSha from '../../graphql/queries/client/commit_sha.graphql'; import getCommitSha from '../../graphql/queries/client/commit_sha.graphql';
import getCurrentBranch from '../../graphql/queries/client/current_branch.graphql'; import getCurrentBranch from '../../graphql/queries/client/current_branch.graphql';
import getIsNewCiConfigFile from '../../graphql/queries/client/is_new_ci_config_file.graphql'; import getIsNewCiConfigFile from '../../graphql/queries/client/is_new_ci_config_file.graphql';
import getPipelineEtag from '../../graphql/queries/client/pipeline_etag.graphql';
import CommitForm from './commit_form.vue'; import CommitForm from './commit_form.vue';
...@@ -94,10 +95,15 @@ export default { ...@@ -94,10 +95,15 @@ export default {
}, },
update(store, { data }) { update(store, { data }) {
const commitSha = data?.commitCreate?.commit?.sha; const commitSha = data?.commitCreate?.commit?.sha;
const pipelineEtag = data?.commitCreate?.commit?.commitPipelinePath;
if (commitSha) { if (commitSha) {
store.writeQuery({ query: getCommitSha, data: { commitSha } }); store.writeQuery({ query: getCommitSha, data: { commitSha } });
} }
if (pipelineEtag) {
store.writeQuery({ query: getPipelineEtag, data: { pipelineEtag } });
}
}, },
}); });
......
...@@ -5,7 +5,11 @@ import { truncateSha } from '~/lib/utils/text_utility'; ...@@ -5,7 +5,11 @@ import { truncateSha } from '~/lib/utils/text_utility';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import getCommitSha from '~/pipeline_editor/graphql/queries/client/commit_sha.graphql'; import getCommitSha from '~/pipeline_editor/graphql/queries/client/commit_sha.graphql';
import getPipelineQuery from '~/pipeline_editor/graphql/queries/client/pipeline.graphql'; import getPipelineQuery from '~/pipeline_editor/graphql/queries/client/pipeline.graphql';
import { toggleQueryPollingByVisibility } from '~/pipelines/components/graph/utils'; import getPipelineEtag from '~/pipeline_editor/graphql/queries/client/pipeline_etag.graphql';
import {
getQueryHeaders,
toggleQueryPollingByVisibility,
} from '~/pipelines/components/graph/utils';
import CiIcon from '~/vue_shared/components/ci_icon.vue'; import CiIcon from '~/vue_shared/components/ci_icon.vue';
const POLL_INTERVAL = 10000; const POLL_INTERVAL = 10000;
...@@ -31,7 +35,13 @@ export default { ...@@ -31,7 +35,13 @@ export default {
commitSha: { commitSha: {
query: getCommitSha, query: getCommitSha,
}, },
pipelineEtag: {
query: getPipelineEtag,
},
pipeline: { pipeline: {
context() {
return getQueryHeaders(this.pipelineEtag);
},
query: getPipelineQuery, query: getPipelineQuery,
variables() { variables() {
return { return {
......
...@@ -22,6 +22,7 @@ mutation commitCIFile( ...@@ -22,6 +22,7 @@ mutation commitCIFile(
commit { commit {
sha sha
} }
commitPipelinePath
errors errors
} }
} }
...@@ -6,6 +6,7 @@ import { resetServiceWorkersPublicPath } from '../lib/utils/webpack'; ...@@ -6,6 +6,7 @@ import { resetServiceWorkersPublicPath } from '../lib/utils/webpack';
import { CODE_SNIPPET_SOURCE_SETTINGS } from './components/code_snippet_alert/constants'; import { CODE_SNIPPET_SOURCE_SETTINGS } from './components/code_snippet_alert/constants';
import getCommitSha from './graphql/queries/client/commit_sha.graphql'; import getCommitSha from './graphql/queries/client/commit_sha.graphql';
import getCurrentBranch from './graphql/queries/client/current_branch.graphql'; import getCurrentBranch from './graphql/queries/client/current_branch.graphql';
import getPipelineEtag from './graphql/queries/client/pipeline_etag.graphql';
import { resolvers } from './graphql/resolvers'; import { resolvers } from './graphql/resolvers';
import typeDefs from './graphql/typedefs.graphql'; import typeDefs from './graphql/typedefs.graphql';
import PipelineEditorApp from './pipeline_editor_app.vue'; import PipelineEditorApp from './pipeline_editor_app.vue';
...@@ -26,6 +27,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -26,6 +27,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
// Add to apollo cache as it can be updated by future queries // Add to apollo cache as it can be updated by future queries
commitSha, commitSha,
initialBranchName, initialBranchName,
pipelineEtag,
// Add to provide/inject API for static values // Add to provide/inject API for static values
ciConfigPath, ciConfigPath,
defaultBranch, defaultBranch,
...@@ -48,7 +50,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -48,7 +50,7 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
Vue.use(VueApollo); Vue.use(VueApollo);
const apolloProvider = new VueApollo({ const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(resolvers, { typeDefs }), defaultClient: createDefaultClient(resolvers, { typeDefs, useGet: true }),
}); });
const { cache } = apolloProvider.clients.defaultClient; const { cache } = apolloProvider.clients.defaultClient;
...@@ -66,6 +68,13 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => { ...@@ -66,6 +68,13 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
}, },
}); });
cache.writeQuery({
query: getPipelineEtag,
data: {
pipelineEtag,
},
});
return new Vue({ return new Vue({
el, el,
apolloProvider, apolloProvider,
......
...@@ -9,14 +9,16 @@ module Ci ...@@ -9,14 +9,16 @@ module Ci
end end
def js_pipeline_editor_data(project) def js_pipeline_editor_data(project)
commit_sha = project.commit ? project.commit.sha : ''
{ {
"ci-config-path": project.ci_config_path_or_default, "ci-config-path": project.ci_config_path_or_default,
"commit-sha" => project.commit ? project.commit.sha : '', "commit-sha" => commit_sha,
"default-branch" => project.default_branch, "default-branch" => project.default_branch,
"empty-state-illustration-path" => image_path('illustrations/empty-state/empty-dag-md.svg'), "empty-state-illustration-path" => image_path('illustrations/empty-state/empty-dag-md.svg'),
"initial-branch-name": params[:branch_name], "initial-branch-name": params[:branch_name],
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'), "lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'),
"new-merge-request-path" => namespace_project_new_merge_request_path, "new-merge-request-path" => namespace_project_new_merge_request_path,
"pipeline_etag" => graphql_etag_pipeline_sha_path(project.commit.sha),
"project-path" => project.path, "project-path" => project.path,
"project-full-path" => project.full_path, "project-full-path" => project.full_path,
"project-namespace" => project.namespace.full_path, "project-namespace" => project.namespace.full_path,
......
...@@ -45,6 +45,7 @@ RSpec.describe Ci::PipelineEditorHelper do ...@@ -45,6 +45,7 @@ RSpec.describe Ci::PipelineEditorHelper do
"initial-branch-name": nil, "initial-branch-name": nil,
"lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'), "lint-help-page-path" => help_page_path('ci/lint', anchor: 'validate-basic-logic-and-syntax'),
"new-merge-request-path" => '/mock/project/-/merge_requests/new', "new-merge-request-path" => '/mock/project/-/merge_requests/new',
"pipeline_etag" => graphql_etag_pipeline_sha_path(project.commit.sha),
"project-path" => project.path, "project-path" => project.path,
"project-full-path" => project.full_path, "project-full-path" => project.full_path,
"project-namespace" => project.namespace.full_path, "project-namespace" => project.namespace.full_path,
......
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