DEV: return populated data at the end of the method. (#13739)
And some minor refactoring.
This commit is contained in:
parent
5cd447695e
commit
74b3730143
|
@ -38,6 +38,7 @@ module DiscourseDev
|
|||
post = PostCreator.new(user, data).create!
|
||||
topic.reload
|
||||
generate_likes(post)
|
||||
post
|
||||
end
|
||||
|
||||
def generate_likes(post)
|
||||
|
@ -63,9 +64,11 @@ module DiscourseDev
|
|||
def populate!
|
||||
generate_likes(topic.first_post)
|
||||
|
||||
@count.times do
|
||||
create!
|
||||
end
|
||||
super(ignore_current_count: true)
|
||||
end
|
||||
|
||||
def current_count
|
||||
topic.posts_count - 1
|
||||
end
|
||||
|
||||
def self.add_replies!(args)
|
||||
|
|
|
@ -29,31 +29,33 @@ module DiscourseDev
|
|||
record
|
||||
end
|
||||
|
||||
def populate!
|
||||
if current_count >= @count
|
||||
puts "Already have #{current_count} #{type} records"
|
||||
def populate!(ignore_current_count: false)
|
||||
unless ignore_current_count
|
||||
if current_count >= @count
|
||||
puts "Already have #{current_count} #{type} records"
|
||||
|
||||
Rake.application.top_level_tasks.each do |task_name|
|
||||
Rake::Task[task_name].reenable
|
||||
Rake.application.top_level_tasks.each do |task_name|
|
||||
Rake::Task[task_name].reenable
|
||||
end
|
||||
|
||||
Rake::Task['dev:repopulate'].invoke
|
||||
return
|
||||
elsif current_count > 0
|
||||
@count -= current_count
|
||||
puts "There are #{current_count} #{type} records. Creating #{@count} more."
|
||||
else
|
||||
puts "Creating #{@count} sample #{type} records"
|
||||
end
|
||||
|
||||
Rake::Task['dev:repopulate'].invoke
|
||||
return
|
||||
elsif current_count > 0
|
||||
@count -= current_count
|
||||
puts "There are #{current_count} #{type} records. Creating #{@count} more."
|
||||
else
|
||||
puts "Creating #{@count} sample #{type} records"
|
||||
end
|
||||
|
||||
records = []
|
||||
@count.times do
|
||||
records << create!
|
||||
putc "."
|
||||
putc "." unless type == :post
|
||||
end
|
||||
|
||||
puts unless type == :post
|
||||
DiscourseEvent.trigger(:after_populate_dev_records, records, type)
|
||||
puts
|
||||
records
|
||||
end
|
||||
|
||||
|
|
|
@ -67,21 +67,24 @@ module DiscourseDev
|
|||
def create!
|
||||
@category = Category.random
|
||||
user = self.user
|
||||
topic = Faker::DiscourseMarkdown.with_user(user.id) { data }
|
||||
post = PostCreator.new(user, topic).create!
|
||||
topic_data = Faker::DiscourseMarkdown.with_user(user.id) { data }
|
||||
post = PostCreator.new(user, topic_data).create!
|
||||
|
||||
if override = @settings.dig(:replies, :overrides).find { |o| o[:title] == topic[:title] }
|
||||
if override = @settings.dig(:replies, :overrides).find { |o| o[:title] == topic_data[:title] }
|
||||
reply_count = override[:count]
|
||||
else
|
||||
reply_count = Faker::Number.between(from: @settings.dig(:replies, :min), to: @settings.dig(:replies, :max))
|
||||
end
|
||||
|
||||
Post.new(post.topic, reply_count).populate!
|
||||
topic = post.topic
|
||||
Post.new(topic, reply_count).populate!
|
||||
topic
|
||||
end
|
||||
|
||||
def populate!
|
||||
super
|
||||
topics = super
|
||||
delete_unwanted_sidekiq_jobs
|
||||
topics
|
||||
end
|
||||
|
||||
def user
|
||||
|
|
Loading…
Reference in New Issue