Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
a7924cd3
Commit
a7924cd3
authored
Aug 05, 2012
by
Mike Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added db:seed_fast
parent
266b9a4d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
19 deletions
+42
-19
Gemfile
+1
-0
Rakefile
+41
-19
No files found.
Gemfile
View file @
a7924cd3
...
@@ -16,6 +16,7 @@ gem 'sqlite3'
...
@@ -16,6 +16,7 @@ gem 'sqlite3'
gem
'
ampex
'
gem
'
ampex
'
gem
'
mongo
'
gem
'
moped
'
gem
'
moped
'
gem
'
mongoid
'
,
"~> 3.0"
gem
'
mongoid
'
,
"~> 3.0"
gem
'
bson_ext
'
gem
'
bson_ext
'
...
...
Rakefile
View file @
a7924cd3
...
@@ -95,9 +95,9 @@ namespace :db do
...
@@ -95,9 +95,9 @@ namespace :db do
Subscription
.
delete_all
Subscription
.
delete_all
end
end
THREADS_PER_COMMENTABLE
=
15
THREADS_PER_COMMENTABLE
=
20
TOP_COMMENTS_PER_THREAD
=
3
TOP_COMMENTS_PER_THREAD
=
4
ADDITIONAL_COMMENTS_PER_THREAD
=
5
ADDITIONAL_COMMENTS_PER_THREAD
=
20
COURSE_ID
=
"MITx/6.002x/2012_Fall"
COURSE_ID
=
"MITx/6.002x/2012_Fall"
...
@@ -152,13 +152,13 @@ namespace :db do
...
@@ -152,13 +152,13 @@ namespace :db do
end
end
end
end
puts
"voting"
#
puts "voting"
(
threads
+
top_comments
+
additional_comments
).
each
do
|
c
|
#
(threads + top_comments + additional_comments).each do |c|
users
.
each
do
|
user
|
#
users.each do |user|
user
.
vote
(
c
,
[
:up
,
:down
].
sample
)
#
user.vote(c, [:up, :down].sample)
end
#
end
end
#
end
puts
"finished"
puts
"finished"
end
end
...
@@ -169,6 +169,28 @@ namespace :db do
...
@@ -169,6 +169,28 @@ namespace :db do
end
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
task
:seed
=>
:environment
do
Comment
.
delete_all
Comment
.
delete_all
...
@@ -180,16 +202,16 @@ namespace :db do
...
@@ -180,16 +202,16 @@ namespace :db do
beginning_time
=
Time
.
now
beginning_time
=
Time
.
now
users
=
(
1
..
10
).
map
{
|
id
|
create_test_user
(
id
)}
users
=
(
1
..
10
).
map
{
|
id
|
create_test_user
(
id
)}
3
.
times
do
#
3.times do
other_user
=
users
[
1
..
9
].
sample
#
other_user = users[1..9].sample
users
.
first
.
subscribe
(
other_user
)
#
users.first.subscribe(other_user)
end
#
end
10
.
times
do
#
10.times do
user
=
users
.
sample
#
user = users.sample
other_user
=
users
.
select
{
|
u
|
u
!=
user
}.
sample
#
other_user = users.select{|u| u != user}.sample
user
.
subscribe
(
other_user
)
#
user.subscribe(other_user)
end
#
end
generate_comments_for
(
"video_1"
)
generate_comments_for
(
"video_1"
)
generate_comments_for
(
"lab_1"
)
generate_comments_for
(
"lab_1"
)
generate_comments_for
(
"lab_2"
)
generate_comments_for
(
"lab_2"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment