summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-09-14 19:40:31 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-09-14 19:40:31 +0530
commit74626106bb688b0b76b30fc00a71627d94806b3a (patch)
tree6f9699f335f2a900ee7ac7d21df0339e1569b79c
parent2110989fe360c2c3a31adc7272524ab83f37de83 (diff)
downloadgitlab-ce-74626106bb688b0b76b30fc00a71627d94806b3a.tar.gz
wip: perf
-rw-r--r--app/models/concerns/issuable.rb3
-rw-r--r--app/models/cycle_analytics/queries.rb4
-rw-r--r--db/fixtures/development/17_cycle_analytics.rb30
3 files changed, 20 insertions, 17 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 22231b2e0f0..1c10ff9fa1b 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -28,6 +28,9 @@ module Issuable
loaded? && to_a.all? { |note| note.association(:award_emoji).loaded? }
end
end
+
+ has_many :system_notes, -> { merge(Note.system) }, class_name: Note, as: :noteable, inverse_of: :noteable
+
has_many :label_links, as: :target, dependent: :destroy
has_many :labels, through: :label_links
has_many :todos, as: :target, dependent: :destroy
diff --git a/app/models/cycle_analytics/queries.rb b/app/models/cycle_analytics/queries.rb
index 32c49ec52ba..861460f1de4 100644
--- a/app/models/cycle_analytics/queries.rb
+++ b/app/models/cycle_analytics/queries.rb
@@ -2,7 +2,7 @@ class CycleAnalytics
module Queries
class << self
def issues(project, created_after:)
- project.issues.where("created_at >= ?", created_after).map { |issue| { issue: issue } }
+ project.issues.where("created_at >= ?", created_after).preload(:metrics, :system_notes).map { |issue| { issue: issue } }
end
def merge_requests_closing_issues(project, options = {})
@@ -29,7 +29,7 @@ class CycleAnalytics
def issue_first_mentioned_in_commit_at
lambda do |data_point|
issue = data_point[:issue]
- commits_mentioning_issue = issue.notes.system.map { |note| note.all_references.commits }.flatten
+ commits_mentioning_issue = issue.system_notes.map { |note| note.all_references.commits }.flatten
commits_mentioning_issue.map(&:committed_date).min if commits_mentioning_issue.present?
end
end
diff --git a/db/fixtures/development/17_cycle_analytics.rb b/db/fixtures/development/17_cycle_analytics.rb
index 5625709af9a..6d5a28c2e81 100644
--- a/db/fixtures/development/17_cycle_analytics.rb
+++ b/db/fixtures/development/17_cycle_analytics.rb
@@ -1,9 +1,10 @@
require 'sidekiq/testing'
class Gitlab::Seeder::CycleAnalytics
- def initialize(project)
+ def initialize(project, perf: false)
@project = project
@user = User.find(1)
+ @issue_count = perf ? 1000 : 5
stub_git_pre_receive!
end
@@ -27,32 +28,26 @@ class Gitlab::Seeder::CycleAnalytics
# Stage 1
Timecop.travel 5.days.from_now
add_milestones_and_list_labels(issues)
- Timecop.return
# Stage 2
- Timecop.travel 10.days.from_now
+ Timecop.travel 5.days.from_now
branches = mention_in_commits(issues)
- Timecop.return
# Stage 3
- Timecop.travel 15.days.from_now
+ Timecop.travel 5.days.from_now
merge_requests = create_merge_requests_closing_issues(issues, branches)
- Timecop.return
# Stage 4
- Timecop.travel 20.days.from_now
+ Timecop.travel 5.days.from_now
run_builds(merge_requests)
- Timecop.return
# Stage 5
- Timecop.travel 25.days.from_now
+ Timecop.travel 5.days.from_now
merge_merge_requests(merge_requests)
- Timecop.return
# Stage 6 / 7
- Timecop.travel 30.days.from_now
+ Timecop.travel 5.days.from_now
deploy_to_production(merge_requests)
- Timecop.return
end
print '.'
@@ -61,7 +56,7 @@ class Gitlab::Seeder::CycleAnalytics
private
def create_issues(project)
- Array.new(5) do
+ Array.new(@issue_count) do
issue_params = {
title: "Cycle Analytics: #{FFaker::Lorem.sentence(6)}",
description: FFaker::Lorem.sentence,
@@ -166,8 +161,13 @@ class Gitlab::Seeder::CycleAnalytics
end
Gitlab::Seeder.quiet do
- Project.all.each do |project|
- seeder = Gitlab::Seeder::CycleAnalytics.new(project)
+ if ENV['SEED_CYCLE_ANALYTICS']
+ seeder = Gitlab::Seeder::CycleAnalytics.new(Project.find(1))
+ seeder.seed!
+ elsif ENV['CYCLE_ANALYTICS_PERF_TEST']
+ seeder = Gitlab::Seeder::CycleAnalytics.new(Project.first, perf: true)
seeder.seed!
+ else
+ puts "Not running the cycle analytics seed file. Use the `SEED_CYCLE_ANALYTICS` environment variable to enable it."
end
end