Commit c8e50827 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'sh-avoid-build-hooks-data' into 'master'

Reduce SQL queries when no pipeline hooks are active

See merge request gitlab-org/gitlab!49186
parents 154dac8c 86ac75f2
...@@ -831,9 +831,8 @@ module Ci ...@@ -831,9 +831,8 @@ module Ci
end end
def execute_hooks def execute_hooks
data = pipeline_data project.execute_hooks(pipeline_data, :pipeline_hooks) if project.has_active_hooks?(:pipeline_hooks)
project.execute_hooks(data, :pipeline_hooks) project.execute_services(pipeline_data, :pipeline_hooks) if project.has_active_services?(:pipeline_hooks)
project.execute_services(data, :pipeline_hooks)
end end
# All the merge requests for which the current pipeline runs/ran against # All the merge requests for which the current pipeline runs/ran against
...@@ -1159,7 +1158,9 @@ module Ci ...@@ -1159,7 +1158,9 @@ module Ci
end end
def pipeline_data def pipeline_data
Gitlab::DataBuilder::Pipeline.build(self) strong_memoize(:pipeline_data) do
Gitlab::DataBuilder::Pipeline.build(self)
end
end end
def merge_request_diff_sha def merge_request_diff_sha
......
---
title: Reduce SQL queries when no pipeline hooks are active
merge_request: 49186
author:
type: performance
...@@ -2578,6 +2578,14 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -2578,6 +2578,14 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
it 'receives a pending event once' do it 'receives a pending event once' do
expect(WebMock).to have_requested_pipeline_hook('pending').once expect(WebMock).to have_requested_pipeline_hook('pending').once
end end
it 'builds hook data once' do
create(:pipelines_email_service, project: project)
expect(Gitlab::DataBuilder::Pipeline).to receive(:build).once.and_call_original
pipeline.execute_hooks
end
end end
context 'when build is run' do context 'when build is run' do
...@@ -2639,6 +2647,12 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -2639,6 +2647,12 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
it 'did not execute pipeline_hook after touched' do it 'did not execute pipeline_hook after touched' do
expect(WebMock).not_to have_requested(:post, hook.url) expect(WebMock).not_to have_requested(:post, hook.url)
end end
it 'does not build hook data' do
expect(Gitlab::DataBuilder::Pipeline).not_to receive(:build)
pipeline.execute_hooks
end
end end
def create_build(name, stage_idx) def create_build(name, stage_idx)
......
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