diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-01-05 17:54:56 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-01-05 17:54:56 +0000 |
commit | 0c3ec51f404d6a976472fe069bd4249fdd65aee1 (patch) | |
tree | 5b8efe62b12bbe30d5863936a6a6d3f7003de25d /db | |
parent | c618e5aa6d1381566616f76676ec9c8903468046 (diff) | |
parent | 06d4f07a041a70fe9462bcae47b1b191908347ab (diff) | |
download | gitlab-ce-0c3ec51f404d6a976472fe069bd4249fdd65aee1.tar.gz |
Merge branch 'issue_40500' into 'master'
Improve filtering issues by label performance
Closes #40500 and #37143
See merge request gitlab-org/gitlab-ce!16136
Diffstat (limited to 'db')
-rw-r--r-- | db/fixtures/development/22_labeled_issues_seed.rb | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/db/fixtures/development/22_labeled_issues_seed.rb b/db/fixtures/development/22_labeled_issues_seed.rb new file mode 100644 index 00000000000..3e4485c7a73 --- /dev/null +++ b/db/fixtures/development/22_labeled_issues_seed.rb @@ -0,0 +1,112 @@ +# Creates a project with labeled issues for a user. +# Run this single seed file using: rake db:seed_fu FILTER=labeled USER_ID=74. +# If an USER_ID is not provided it will use the last created user. +require './spec/support/sidekiq' + +class Gitlab::Seeder::LabeledIssues + include ::Gitlab::Utils + + def initialize(user) + @user = user + end + + def seed! + Sidekiq::Testing.inline! do + group = create_group + puts '.' + + create_projects(group) + puts '.' + + create_labels(group) + puts '.' + + create_issues(group) + puts '.' + end + + print '.' + end + + private + + def create_group + group_name = "group_of_#{@user.name}#{SecureRandom.hex(4)}" + + group = Group.new( + name: group_name, + path: group_name, + description: FFaker::Lorem.sentence + ) + + group.save + + group.add_owner(@user) + + group + end + + def create_projects(group) + 5.times do + project_name = "project_#{SecureRandom.hex(6)}" + params = { + namespace_id: group.id, + name: project_name, + description: FFaker::Lorem.sentence, + visibility_level: Gitlab::VisibilityLevel.values.sample + } + + Projects::CreateService.new(@user, params).execute + end + end + + def create_labels(group) + group.projects.each do |project| + 5.times do + label_title = FFaker::Vehicle.model + Labels::CreateService.new(title: label_title).execute(project: project) + end + end + + 10.times do + label_title = FFaker::Product.brand + Labels::CreateService.new(title: label_title).execute(group: group) + end + end + + def create_issues(group) + # Get only group labels + group_labels = + LabelsFinder.new(@user, group_id: group.id).execute.where.not(group_id: nil) + + group.projects.each do |project| + label_ids = project.labels.pluck(:id).sample(5) + label_ids.push(*group.labels.sample(4)) + + 50.times do + issue_params = { + title: FFaker::Lorem.sentence(6), + description: FFaker::Lorem.sentence, + state: 'opened', + label_ids: label_ids + + } + + Issues::CreateService.new(project, @user, issue_params).execute if project.project_feature.present? + end + end + end +end + +Gitlab::Seeder.quiet do + user_id = ENV['USER_ID'] + + user = + if user_id.present? + User.find(user_id) + else + User.last + end + + Gitlab::Seeder::LabeledIssues.new(user).seed! +end |