Commit 74626106 authored by Timothy Andrew's avatar Timothy Andrew

wip: perf

parent 2110989f
...@@ -28,6 +28,9 @@ module Issuable ...@@ -28,6 +28,9 @@ module Issuable
loaded? && to_a.all? { |note| note.association(:award_emoji).loaded? } loaded? && to_a.all? { |note| note.association(:award_emoji).loaded? }
end end
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 :label_links, as: :target, dependent: :destroy
has_many :labels, through: :label_links has_many :labels, through: :label_links
has_many :todos, as: :target, dependent: :destroy has_many :todos, as: :target, dependent: :destroy
......
...@@ -2,7 +2,7 @@ class CycleAnalytics ...@@ -2,7 +2,7 @@ class CycleAnalytics
module Queries module Queries
class << self class << self
def issues(project, created_after:) 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 end
def merge_requests_closing_issues(project, options = {}) def merge_requests_closing_issues(project, options = {})
...@@ -29,7 +29,7 @@ class CycleAnalytics ...@@ -29,7 +29,7 @@ class CycleAnalytics
def issue_first_mentioned_in_commit_at def issue_first_mentioned_in_commit_at
lambda do |data_point| lambda do |data_point|
issue = data_point[:issue] 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? commits_mentioning_issue.map(&:committed_date).min if commits_mentioning_issue.present?
end end
end end
......
require 'sidekiq/testing' require 'sidekiq/testing'
class Gitlab::Seeder::CycleAnalytics class Gitlab::Seeder::CycleAnalytics
def initialize(project) def initialize(project, perf: false)
@project = project @project = project
@user = User.find(1) @user = User.find(1)
@issue_count = perf ? 1000 : 5
stub_git_pre_receive! stub_git_pre_receive!
end end
...@@ -27,32 +28,26 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -27,32 +28,26 @@ class Gitlab::Seeder::CycleAnalytics
# Stage 1 # Stage 1
Timecop.travel 5.days.from_now Timecop.travel 5.days.from_now
add_milestones_and_list_labels(issues) add_milestones_and_list_labels(issues)
Timecop.return
# Stage 2 # Stage 2
Timecop.travel 10.days.from_now Timecop.travel 5.days.from_now
branches = mention_in_commits(issues) branches = mention_in_commits(issues)
Timecop.return
# Stage 3 # Stage 3
Timecop.travel 15.days.from_now Timecop.travel 5.days.from_now
merge_requests = create_merge_requests_closing_issues(issues, branches) merge_requests = create_merge_requests_closing_issues(issues, branches)
Timecop.return
# Stage 4 # Stage 4
Timecop.travel 20.days.from_now Timecop.travel 5.days.from_now
run_builds(merge_requests) run_builds(merge_requests)
Timecop.return
# Stage 5 # Stage 5
Timecop.travel 25.days.from_now Timecop.travel 5.days.from_now
merge_merge_requests(merge_requests) merge_merge_requests(merge_requests)
Timecop.return
# Stage 6 / 7 # Stage 6 / 7
Timecop.travel 30.days.from_now Timecop.travel 5.days.from_now
deploy_to_production(merge_requests) deploy_to_production(merge_requests)
Timecop.return
end end
print '.' print '.'
...@@ -61,7 +56,7 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -61,7 +56,7 @@ class Gitlab::Seeder::CycleAnalytics
private private
def create_issues(project) def create_issues(project)
Array.new(5) do Array.new(@issue_count) do
issue_params = { issue_params = {
title: "Cycle Analytics: #{FFaker::Lorem.sentence(6)}", title: "Cycle Analytics: #{FFaker::Lorem.sentence(6)}",
description: FFaker::Lorem.sentence, description: FFaker::Lorem.sentence,
...@@ -166,8 +161,13 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -166,8 +161,13 @@ class Gitlab::Seeder::CycleAnalytics
end end
Gitlab::Seeder.quiet do Gitlab::Seeder.quiet do
Project.all.each do |project| if ENV['SEED_CYCLE_ANALYTICS']
seeder = Gitlab::Seeder::CycleAnalytics.new(project) 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! seeder.seed!
else
puts "Not running the cycle analytics seed file. Use the `SEED_CYCLE_ANALYTICS` environment variable to enable it."
end end
end end
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