Commit 74626106 authored by Timothy Andrew's avatar Timothy Andrew

wip: perf

parent 2110989f
......@@ -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
......
......@@ -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
......
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
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