DEV: return populated data at the end of the method. (#13739)

And some minor refactoring.
This commit is contained in:
Vinoth Kannan
2021-07-15 17:45:32 +05:30
committed by GitHub
parent 5cd447695e
commit 74b3730143
3 changed files with 31 additions and 23 deletions

View File

@ -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