Create script to generate dummy data, for perf investigation

This commit is contained in:
rubic0n 2021-02-03 01:06:42 -06:00
parent 1179957a32
commit 6221581cf0
3 changed files with 42 additions and 5 deletions

View File

@ -111,7 +111,6 @@ end
group :test do group :test do
gem 'capybara', '~> 3.22' gem 'capybara', '~> 3.22'
gem 'climate_control', '~> 0.2' gem 'climate_control', '~> 0.2'
gem 'faker', '~> 1.9'
gem 'microformats', '~> 4.1' gem 'microformats', '~> 4.1'
gem 'rails-controller-testing', '~> 1.0' gem 'rails-controller-testing', '~> 1.0'
gem 'rspec-sidekiq', '~> 3.0' gem 'rspec-sidekiq', '~> 3.0'
@ -126,6 +125,7 @@ group :development do
gem 'better_errors', '~> 2.5' gem 'better_errors', '~> 2.5'
gem 'binding_of_caller', '~> 0.7' gem 'binding_of_caller', '~> 0.7'
gem 'bullet', '~> 6.0' gem 'bullet', '~> 6.0'
gem 'faker', '~> 2.15'
gem 'listen' gem 'listen'
gem 'letter_opener', '~> 1.7' gem 'letter_opener', '~> 1.7'
gem 'letter_opener_web', '~> 1.3' gem 'letter_opener_web', '~> 1.3'

View File

@ -227,8 +227,8 @@ GEM
tzinfo tzinfo
excon (0.78.1) excon (0.78.1)
fabrication (2.21.1) fabrication (2.21.1)
faker (1.9.6) faker (2.15.1)
i18n (>= 0.7) i18n (>= 1.6, < 2)
faraday (1.3.0) faraday (1.3.0)
faraday-net_http (~> 1.0) faraday-net_http (~> 1.0)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
@ -296,7 +296,7 @@ GEM
httplog (1.4.3) httplog (1.4.3)
rack (>= 1.0) rack (>= 1.0)
rainbow (>= 2.0.0) rainbow (>= 2.0.0)
i18n (1.8.7) i18n (1.8.8)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
i18n-tasks (0.9.33) i18n-tasks (0.9.33)
activesupport (>= 4.0.2) activesupport (>= 4.0.2)
@ -703,7 +703,7 @@ DEPENDENCIES
dotenv-rails (~> 2.7) dotenv-rails (~> 2.7)
elastic-apm (~> 3.13) elastic-apm (~> 3.13)
fabrication (~> 2.20) fabrication (~> 2.20)
faker (~> 1.9) faker (~> 2.15)
fast_blank (~> 1.0) fast_blank (~> 1.0)
fastimage fastimage
fog-core (<= 2.1.0) fog-core (<= 2.1.0)

37
lib/tasks/dummy_data.rake Normal file
View File

@ -0,0 +1,37 @@
# frozen_string_literal: true
desc 'Import dummy data into the database, to create a more realistic development experience'
task dummy_data: :environment do
raise 'Only run this in development' unless Rails.env.development?
domain = ENV['LOCAL_DOMAIN'] || Rails.configuration.x.local_domain
admin = Account.find_by!(username: 'admin')
accounts = 1.upto(1_000).map do |num|
username = "#{Faker::Internet.username(separators: %w[_])}#{num}"
password = Faker::Internet.password
Account.create!(username: username).tap do |account|
account.create_user!({
email: "#{username}@#{domain}",
password: password,
password_confirmation: password,
agreement: true,
approved: true
})
end
end
accounts.each do |acct|
FollowService.new.call(admin, acct)
end
statuses = (accounts + [admin]).map do |account|
PostStatusService.new.call(account, text: Faker::Lorem.paragraph(sentence_count: 20))
end
accounts.sample(200).zip(statuses.sample(200)).each do |account, status|
ReblogService.new.call(account, status)
end
end