diff options
author | Alexandru Croitor <acroitor@gitlab.com> | 2019-08-20 16:48:03 +0300 |
---|---|---|
committer | Alexandru Croitor <acroitor@gitlab.com> | 2019-08-21 16:10:20 +0300 |
commit | 84ed493507e1818ee239fd8c780ec704386de21a (patch) | |
tree | 29e06538bd15b7b354eb62742007fc96fff088f4 | |
parent | 68d745835c80b8b045de1d42887e91fb0e66a3b6 (diff) | |
download | gitlab-ce-7332-inherit-epic-dates-ce.tar.gz |
Improve epic inherited dates update performance7332-inherit-epic-dates-ce
* Uses a single update statement to update start_date, due_date,
start_date_sourcing_milestone_id, start_date_sourcing_epic_id,
due_date_sourcing_milestone_id, due_date_sourcing_epic_id
* Moves inherited dates update of multiple epics to an async worker
-rw-r--r-- | config/sidekiq_queues.yml | 1 | ||||
-rw-r--r-- | lib/gitlab/sql/union.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/sql/recursive_cte_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/sql/union_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/concerns/from_union_spec.rb | 6 |
5 files changed, 8 insertions, 7 deletions
diff --git a/config/sidekiq_queues.yml b/config/sidekiq_queues.yml index ea165508d29..92fbdc46fc1 100644 --- a/config/sidekiq_queues.yml +++ b/config/sidekiq_queues.yml @@ -114,3 +114,4 @@ - [export_csv, 1] - [incident_management, 2] - [jira_connect, 1] + - [update_epics_dates, 2] diff --git a/lib/gitlab/sql/union.rb b/lib/gitlab/sql/union.rb index f05592fc3a3..4c9e0cd5cdf 100644 --- a/lib/gitlab/sql/union.rb +++ b/lib/gitlab/sql/union.rb @@ -29,7 +29,7 @@ module Gitlab end if fragments.any? - fragments.join("\n#{union_keyword}\n") + fragments.join(")\n#{union_keyword}\n(").prepend('(').concat(')') else 'NULL' end diff --git a/spec/lib/gitlab/sql/recursive_cte_spec.rb b/spec/lib/gitlab/sql/recursive_cte_spec.rb index 407a4d8a247..d45bc67e4a1 100644 --- a/spec/lib/gitlab/sql/recursive_cte_spec.rb +++ b/spec/lib/gitlab/sql/recursive_cte_spec.rb @@ -18,7 +18,7 @@ describe Gitlab::SQL::RecursiveCTE do [rel1.except(:order).to_sql, rel2.except(:order).to_sql] end - expect(sql).to eq("#{name} AS (#{sql1}\nUNION\n#{sql2})") + expect(sql).to eq("#{name} AS ((#{sql1})\nUNION\n(#{sql2}))") end end diff --git a/spec/lib/gitlab/sql/union_spec.rb b/spec/lib/gitlab/sql/union_spec.rb index fe6422c32b6..b77bd3a1d2a 100644 --- a/spec/lib/gitlab/sql/union_spec.rb +++ b/spec/lib/gitlab/sql/union_spec.rb @@ -12,7 +12,7 @@ describe Gitlab::SQL::Union do it 'returns a String joining relations together using a UNION' do union = described_class.new([relation_1, relation_2]) - expect(union.to_sql).to eq("#{to_sql(relation_1)}\nUNION\n#{to_sql(relation_2)}") + expect(union.to_sql).to eq("(#{to_sql(relation_1)})\nUNION\n(#{to_sql(relation_2)})") end it 'skips Model.none segements' do @@ -20,7 +20,7 @@ describe Gitlab::SQL::Union do union = described_class.new([empty_relation, relation_1, relation_2]) expect {User.where("users.id IN (#{union.to_sql})").to_a}.not_to raise_error - expect(union.to_sql).to eq("#{to_sql(relation_1)}\nUNION\n#{to_sql(relation_2)}") + expect(union.to_sql).to eq("(#{to_sql(relation_1)})\nUNION\n(#{to_sql(relation_2)})") end it 'uses UNION ALL when removing duplicates is disabled' do diff --git a/spec/models/concerns/from_union_spec.rb b/spec/models/concerns/from_union_spec.rb index ee427a667c6..735e14b47ec 100644 --- a/spec/models/concerns/from_union_spec.rb +++ b/spec/models/concerns/from_union_spec.rb @@ -15,7 +15,7 @@ describe FromUnion do it 'selects from the results of the UNION' do query = model.from_union([model.where(id: 1), model.where(id: 2)]) - expect(query.to_sql).to match(/FROM \(SELECT.+UNION.+SELECT.+\) users/m) + expect(query.to_sql).to match(/FROM \(\(SELECT.+\)\nUNION\n\(SELECT.+\)\) users/m) end it 'supports the use of a custom alias for the sub query' do @@ -24,7 +24,7 @@ describe FromUnion do alias_as: 'kittens' ) - expect(query.to_sql).to match(/FROM \(SELECT.+UNION.+SELECT.+\) kittens/m) + expect(query.to_sql).to match(/FROM \(\(SELECT.+\)\nUNION\n\(SELECT.+\)\) kittens/m) end it 'supports keeping duplicate rows' do @@ -34,7 +34,7 @@ describe FromUnion do ) expect(query.to_sql) - .to match(/FROM \(SELECT.+UNION ALL.+SELECT.+\) users/m) + .to match(/FROM \(\(SELECT.+\)\nUNION ALL\n\(SELECT.+\)\) users/m) end end end |