From a7924cd351d67c342bad96f1bfb458e75ce92830 Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Sun, 5 Aug 2012 17:42:18 -0400 Subject: [PATCH] added db:seed_fast --- Gemfile | 1 + Rakefile | 58 ++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index c1c4290..3eefd08 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem 'sqlite3' gem 'ampex' +gem 'mongo' gem 'moped' gem 'mongoid', "~> 3.0" gem 'bson_ext' diff --git a/Rakefile b/Rakefile index 31ecc85..3c107c1 100644 --- a/Rakefile +++ b/Rakefile @@ -95,9 +95,9 @@ namespace :db do Subscription.delete_all end - THREADS_PER_COMMENTABLE = 15 - TOP_COMMENTS_PER_THREAD = 3 - ADDITIONAL_COMMENTS_PER_THREAD = 5 + THREADS_PER_COMMENTABLE = 20 + TOP_COMMENTS_PER_THREAD = 4 + ADDITIONAL_COMMENTS_PER_THREAD = 20 COURSE_ID = "MITx/6.002x/2012_Fall" @@ -152,13 +152,13 @@ namespace :db do end end - puts "voting" + # puts "voting" - (threads + top_comments + additional_comments).each do |c| - users.each do |user| - user.vote(c, [:up, :down].sample) - end - end + # (threads + top_comments + additional_comments).each do |c| + # users.each do |user| + # user.vote(c, [:up, :down].sample) + # end + # end puts "finished" end @@ -169,6 +169,28 @@ namespace :db do end + task :seed_fast => :environment do + ADDITIONAL_COMMENTS_PER_THREAD = 20 + + + config = YAML.load_file("config/mongoid.yml")[Sinatra::Base.environment]["sessions"]["default"] + connnection = Mongo::Connection.new(config["hosts"][0].split(":")[0], config["hosts"][0].split(":")[1]) + db = Mongo::Connection.new.db(config["database"]) + coll = db.collection("contents") + Comment.delete_all + CommentThread.each do |thread| + ADDITIONAL_COMMENTS_PER_THREAD.times do + doc = {"_type" => "Comment", "anonymous" => false, "at_position_list" => [], + "author_id" => rand(1..10).to_s, "body" => Faker::Lorem.paragraphs.join("\n\n"), + "comment_thread_id" => BSON::ObjectId.from_string(thread.id.to_s), "course_id" => COURSE_ID, + "created_at" => Time.now, + "endorsed" => [true, false].sample, "parent_ids" => [], "updated_at" => Time.now, + "votes" => {"count" => 0, "down" => [], "down_count" => 0, "point" => 0, "up" => [], "up_count" => []}} + coll.insert(doc) + end + end + end + task :seed => :environment do Comment.delete_all @@ -180,16 +202,16 @@ namespace :db do beginning_time = Time.now users = (1..10).map {|id| create_test_user(id)} - 3.times do - other_user = users[1..9].sample - users.first.subscribe(other_user) - end + # 3.times do + # other_user = users[1..9].sample + # users.first.subscribe(other_user) + # end - 10.times do - user = users.sample - other_user = users.select{|u| u != user}.sample - user.subscribe(other_user) - end + # 10.times do + # user = users.sample + # other_user = users.select{|u| u != user}.sample + # user.subscribe(other_user) + # end generate_comments_for("video_1") generate_comments_for("lab_1") generate_comments_for("lab_2")