Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

FIX: Don't try to create more records than we need #9

Merged
merged 2 commits into from May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/discourse_dev/post.rb
Expand Up @@ -63,8 +63,7 @@ def user
def populate!
generate_likes(topic.first_post)

@count.times do |i|
@index = i
@count.times do
create!
end
end
Expand All @@ -86,7 +85,6 @@ def self.add_replies!(args)
puts "Creating #{count} replies in '#{topic.title}'"

count.times do |i|
@index = i
begin
user = User.random
reply = Faker::DiscourseMarkdown.with_user(user.id) do
Expand Down
17 changes: 7 additions & 10 deletions lib/discourse_dev/record.rb
Expand Up @@ -20,7 +20,6 @@ def initialize(model, count = DEFAULT_COUNT)
@model = model
@type = model.to_s
@count = count
@index = nil
end

def create!
Expand All @@ -30,31 +29,29 @@ def create!

def populate!
if current_count >= @count
puts "Already have #{@count}+ #{type.downcase} records."
puts "Already have #{current_count} #{type.downcase} records"

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.downcase} records. Creating #{@count} more."
else
puts "Creating #{@count} sample #{type.downcase} records"
end

puts "Creating #{@count} sample #{type.downcase} records"

@count.times do |i|
@index = i
@count.times do
create!
putc "."
end

puts
end

def index
@index
end

def current_count
model.count
end
Expand Down
2 changes: 1 addition & 1 deletion lib/discourse_dev/tasks/dev.rake
Expand Up @@ -42,6 +42,6 @@ task 'dev:repopulate' => ['db:load_config'] do |_, args|
if (answer == "" || answer.downcase == 'y')
Rake::Task['dev:reset'].invoke
else
puts "You can run `dev:reset` rake task to do this repopulate action anytime."
puts "You can run `bin/rails dev:reset` to repopulate anytime."
end
end
2 changes: 1 addition & 1 deletion lib/discourse_dev/topic.rb
Expand Up @@ -45,7 +45,7 @@ def data
end

def title
if index < I18n.t("faker.discourse.topics").count
if current_count < I18n.t("faker.discourse.topics").count
Faker::Discourse.unique.topic
else
Faker::Lorem.unique.sentence(word_count: 5, supplemental: true, random_words_to_add: 4).chomp(".")
Expand Down