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
d50568f4
Commit
d50568f4
authored
Aug 16, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed index bug
parent
aaa72d0f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
51 additions
and
69 deletions
+51
-69
Rakefile
+15
-21
api/commentables.rb
+0
-2
config/benchmark.yml
+7
-7
lib/tasks/benchmark.rake
+17
-19
models/comment.rb
+1
-0
models/comment_thread.rb
+5
-1
models/content.rb
+1
-5
spec/api/comment_thread_spec.rb
+2
-2
spec/benchmark/bulk_generate_spec.rb
+0
-0
spec/spec_helper.rb
+3
-12
No files found.
Rakefile
View file @
d50568f4
...
@@ -4,7 +4,6 @@ require 'bundler'
...
@@ -4,7 +4,6 @@ require 'bundler'
Bundler
.
setup
Bundler
.
setup
Bundler
.
require
Bundler
.
require
desc
"Load the environment"
desc
"Load the environment"
task
:environment
do
task
:environment
do
environment
=
ENV
[
"SINATRA_ENV"
]
||
"development"
environment
=
ENV
[
"SINATRA_ENV"
]
||
"development"
...
@@ -30,7 +29,7 @@ def create_test_user(id)
...
@@ -30,7 +29,7 @@ def create_test_user(id)
User
.
create!
(
external_id:
id
,
username:
"user
#{
id
}
"
,
email:
"user
#{
id
}
@test.com"
)
User
.
create!
(
external_id:
id
,
username:
"user
#{
id
}
"
,
email:
"user
#{
id
}
@test.com"
)
end
end
#
Dir.glob('lib/tasks/*.rake').each { |r| import r }
Dir
.
glob
(
'lib/tasks/*.rake'
).
each
{
|
r
|
import
r
}
task
:console
=>
:environment
do
task
:console
=>
:environment
do
binding
.
pry
binding
.
pry
...
@@ -38,28 +37,23 @@ end
...
@@ -38,28 +37,23 @@ end
namespace
:db
do
namespace
:db
do
task
:init
=>
:environment
do
task
:init
=>
:environment
do
puts
"creating indexes..."
puts
"recreating indexes..."
Comment
.
create_indexes
[
Comment
,
CommentThread
,
User
,
Notification
,
Subscription
,
Activity
,
Delayed
::
Backend
::
Mongoid
::
Job
].
each
(
&
:remove_indexes
).
each
(
&
:create_indexes
)
CommentThread
.
create_indexes
User
.
create_indexes
Notification
.
create_indexes
Subscription
.
create_indexes
Delayed
::
Backend
::
Mongoid
::
Job
.
create_indexes
puts
"finished"
puts
"finished"
end
end
task
:clean
=>
:environment
do
task
:clean
=>
:environment
do
Comment
.
delete_all
Comment
.
delete_all
CommentThread
.
delete_all
CommentThread
.
delete_all
Co
ntent
.
recalculate_all_context_tag_weights!
Co
mmentThread
.
recalculate_all_context_tag_weights!
User
.
delete_all
User
.
delete_all
Notification
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
Subscription
.
delete_all
end
end
THREADS_PER_COMMENTABLE
=
20
THREADS_PER_COMMENTABLE
=
20
TOP_COMMENTS_PER_THREAD
=
4
TOP_COMMENTS_PER_THREAD
=
3
ADDITIONAL_COMMENTS_PER_THREAD
=
20
ADDITIONAL_COMMENTS_PER_THREAD
=
4
COURSE_ID
=
"MITx/6.002x/2012_Fall"
COURSE_ID
=
"MITx/6.002x/2012_Fall"
...
@@ -115,13 +109,13 @@ namespace :db do
...
@@ -115,13 +109,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
...
@@ -183,7 +177,7 @@ namespace :db do
...
@@ -183,7 +177,7 @@ namespace :db do
Comment
.
delete_all
Comment
.
delete_all
CommentThread
.
delete_all
CommentThread
.
delete_all
Co
ntent
.
recalculate_all_context_tag_weights!
Co
mmentThread
.
recalculate_all_context_tag_weights!
User
.
delete_all
User
.
delete_all
Notification
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
Subscription
.
delete_all
...
@@ -204,8 +198,8 @@ namespace :db do
...
@@ -204,8 +198,8 @@ namespace :db do
# 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"
)
end_time
=
Time
.
now
end_time
=
Time
.
now
...
...
api/commentables.rb
View file @
d50568f4
...
@@ -10,7 +10,6 @@ get "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
...
@@ -10,7 +10,6 @@ get "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
end
end
post
"
#{
APIPREFIX
}
/:commentable_id/threads"
do
|
commentable_id
|
post
"
#{
APIPREFIX
}
/:commentable_id/threads"
do
|
commentable_id
|
puts
"creating thread"
thread
=
CommentThread
.
new
(
params
.
slice
(
*
%w[title body course_id]
).
merge
(
commentable_id:
commentable_id
))
thread
=
CommentThread
.
new
(
params
.
slice
(
*
%w[title body course_id]
).
merge
(
commentable_id:
commentable_id
))
thread
.
anonymous
=
bool_anonymous
||
false
thread
.
anonymous
=
bool_anonymous
||
false
thread
.
tags
=
params
[
"tags"
]
||
""
thread
.
tags
=
params
[
"tags"
]
||
""
...
@@ -22,5 +21,4 @@ post "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
...
@@ -22,5 +21,4 @@ post "#{APIPREFIX}/:commentable_id/threads" do |commentable_id|
user
.
subscribe
(
thread
)
if
bool_auto_subscribe
user
.
subscribe
(
thread
)
if
bool_auto_subscribe
thread
.
to_hash
.
to_json
thread
.
to_hash
.
to_json
end
end
puts
CommentThread
.
count
end
end
config/benchmark.yml
View file @
d50568f4
seed_size
:
seed_size
:
commentables
:
20
commentables
:
1
users
:
20
users
:
1
threads
:
20
threads
:
5
top_comments
:
10
0
top_comments
:
0
sub_comments
:
10
0
sub_comments
:
0
votes
:
10
0
votes
:
0
tags
:
100
0
tags
:
0
lib/tasks/benchmark.rake
View file @
d50568f4
require
'rest_client'
require
'rest_client'
namespace
:benchmark
do
namespace
:benchmark
do
task
:bulk_generate
do
task
:bulk_generate
=>
:environment
do
#
[Comment, CommentThread, User, Notification, Subscription].each(&:delete_all).each(&:create_indexes)
[
Comment
,
CommentThread
,
User
,
Notification
,
Subscription
].
each
(
&
:delete_all
).
each
(
&
:create_indexes
)
#
Delayed::Backend::Mongoid::Job.create_indexes
Delayed
::
Backend
::
Mongoid
::
Job
.
create_indexes
seed_config
=
YAML
.
load_file
(
"config/benchmark.yml"
).
with_indifferent_access
seed_config
=
YAML
.
load_file
(
"config/benchmark.yml"
).
with_indifferent_access
...
@@ -18,18 +18,18 @@ namespace :benchmark do
...
@@ -18,18 +18,18 @@ namespace :benchmark do
PREFIX
=
"http://localhost:4567/api/v1"
PREFIX
=
"http://localhost:4567/api/v1"
#
Benchmark.bm(31) do |x|
Benchmark
.
bm
(
31
)
do
|
x
|
RestClient
.
get
"
#{
PREFIX
}
/clean"
RestClient
.
get
"
#{
PREFIX
}
/clean"
#
x.report "create users via api" do
x
.
report
"create users via api"
do
(
1
..
USERS
).
each
do
|
user_id
|
(
1
..
USERS
).
each
do
|
user_id
|
data
=
{
id:
user_id
,
username:
"user
#{
user_id
}
"
,
email:
"user
#{
user_id
}
@test.com"
}
data
=
{
id:
user_id
,
username:
"user
#{
user_id
}
"
,
email:
"user
#{
user_id
}
@test.com"
}
RestClient
.
post
"
#{
PREFIX
}
/users"
,
data
RestClient
.
post
"
#{
PREFIX
}
/users"
,
data
end
end
#
end
end
#
x.report "create new threads via api" do
x
.
report
"create new threads via api"
do
(
1
..
THREADS
).
each
do
|
t
|
(
1
..
THREADS
).
each
do
|
t
|
data
=
{
title:
"Interesting question"
,
body:
"cool"
,
anonymous:
false
,
\
data
=
{
title:
"Interesting question"
,
body:
"cool"
,
anonymous:
false
,
\
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
,
\
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
,
\
...
@@ -38,39 +38,37 @@ namespace :benchmark do
...
@@ -38,39 +38,37 @@ namespace :benchmark do
RestClient
.
post
"
#{
PREFIX
}
/question_
#{
rand
(
COMMENTABLES
).
to_s
}
/threads"
,
data
RestClient
.
post
"
#{
PREFIX
}
/question_
#{
rand
(
COMMENTABLES
).
to_s
}
/threads"
,
data
end
end
#
end
end
#
comment_thread_ids = CommentThread.all.to_a.map(&:id)
comment_thread_ids
=
CommentThread
.
all
.
to_a
.
map
(
&
:id
)
#binding.pry
x
.
report
(
"create top comments via api"
)
do
#x.report("create top comments via api") do
TOP_COMMENTS
.
times
do
TOP_COMMENTS
.
times
do
data
=
{
body:
"lalala"
,
anonymous:
false
,
data
=
{
body:
"lalala"
,
anonymous:
false
,
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
}
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
}
RestClient
.
post
"
#{
PREFIX
}
/threads/
#{
comment_thread_ids
.
sample
}
/comments"
,
data
RestClient
.
post
"
#{
PREFIX
}
/threads/
#{
comment_thread_ids
.
sample
}
/comments"
,
data
end
end
#
end
end
#
top_comment_ids = Comment.all.to_a.map(&:id)
top_comment_ids
=
Comment
.
all
.
to_a
.
map
(
&
:id
)
#
x.report("create sub comments") do
x
.
report
(
"create sub comments"
)
do
SUB_COMMENTS
.
times
do
SUB_COMMENTS
.
times
do
data
=
{
body:
"lalala"
,
anonymous:
false
,
data
=
{
body:
"lalala"
,
anonymous:
false
,
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
}
course_id:
"1"
,
user_id:
(
rand
(
USERS
)
+
1
).
to_s
}
RestClient
.
post
"
#{
PREFIX
}
/comments/
#{
top_comment_ids
.
sample
}
"
,
data
RestClient
.
post
"
#{
PREFIX
}
/comments/
#{
top_comment_ids
.
sample
}
"
,
data
end
end
#
end
end
#
x.report("create votes") do
x
.
report
(
"create votes"
)
do
VOTES
.
times
do
VOTES
.
times
do
data
=
{
user_id:
(
rand
(
USERS
)
+
1
).
to_s
,
value:
[
:up
,
:down
].
sample
}
data
=
{
user_id:
(
rand
(
USERS
)
+
1
).
to_s
,
value:
[
:up
,
:down
].
sample
}
RestClient
.
put
"
#{
PREFIX
}
/threads/
#{
comment_thread_ids
.
sample
}
/votes"
,
data
RestClient
.
put
"
#{
PREFIX
}
/threads/
#{
comment_thread_ids
.
sample
}
/votes"
,
data
RestClient
.
put
"
#{
PREFIX
}
/comments/
#{
top_comment_ids
.
sample
}
/votes"
,
data
RestClient
.
put
"
#{
PREFIX
}
/comments/
#{
top_comment_ids
.
sample
}
/votes"
,
data
end
end
#
end
end
end
end
#
end
end
end
end
models/comment.rb
View file @
d50568f4
require_relative
'content'
require_relative
'content'
class
Comment
<
Content
class
Comment
<
Content
include
Mongoid
::
Tree
include
Mongoid
::
Tree
include
Mongo
::
Voteable
include
Mongo
::
Voteable
include
Mongoid
::
Timestamps
include
Mongoid
::
Timestamps
...
...
models/comment_thread.rb
View file @
d50568f4
require_relative
'content'
require_relative
'content'
class
CommentThread
<
Content
class
CommentThread
<
Content
include
Mongo
::
Voteable
include
Mongo
::
Voteable
include
Mongoid
::
Timestamps
include
Mongoid
::
Timestamps
include
Mongoid
::
TaggableWithContext
include
Mongoid
::
TaggableWithContext
::
AggregationStrategy
::
RealTime
taggable
separator:
','
,
default:
[],
sparse_index:
true
voteable
self
,
:up
=>
+
1
,
:down
=>
-
1
voteable
self
,
:up
=>
+
1
,
:down
=>
-
1
...
...
models/content.rb
View file @
d50568f4
class
Content
class
Content
include
Mongoid
::
Document
include
Mongoid
::
Document
include
Mongoid
::
TaggableWithContext
include
Mongoid
::
TaggableWithContext
::
AggregationStrategy
::
RealTime
taggable
separator:
','
,
default:
[]
def
author_with_anonymity
(
attr
=
nil
,
attr_when_anonymous
=
nil
)
def
author_with_anonymity
(
attr
=
nil
,
attr_when_anonymous
=
nil
)
if
not
attr
if
not
attr
anonymous
?
nil
:
author
anonymous
?
nil
:
author
...
...
spec/api/comment_thread_spec.rb
View file @
d50568f4
...
@@ -137,7 +137,7 @@ describe "app" do
...
@@ -137,7 +137,7 @@ describe "app" do
end
end
describe
"GET /api/v1/threads/tags"
do
describe
"GET /api/v1/threads/tags"
do
it
"get all tags used in threads"
do
it
"get all tags used in threads"
do
Co
ntent
.
recalculate_all_context_tag_weights!
Co
mmentThread
.
recalculate_all_context_tag_weights!
thread1
=
CommentThread
.
all
.
to_a
.
first
thread1
=
CommentThread
.
all
.
to_a
.
first
thread2
=
CommentThread
.
all
.
to_a
.
last
thread2
=
CommentThread
.
all
.
to_a
.
last
thread1
.
tags
=
"a, b, c"
thread1
.
tags
=
"a, b, c"
...
@@ -162,7 +162,7 @@ describe "app" do
...
@@ -162,7 +162,7 @@ describe "app" do
end
end
it
"returns autocomplete results"
do
it
"returns autocomplete results"
do
CommentThread
.
delete_all
CommentThread
.
delete_all
Co
ntent
.
recalculate_all_context_tag_weights!
Co
mmentThread
.
recalculate_all_context_tag_weights!
create_comment_thread
"c++, clojure, common-lisp, c#, c, coffeescript"
create_comment_thread
"c++, clojure, common-lisp, c#, c, coffeescript"
create_comment_thread
"c++, clojure, common-lisp, c#, c"
create_comment_thread
"c++, clojure, common-lisp, c#, c"
create_comment_thread
"c++, clojure, common-lisp, c#"
create_comment_thread
"c++, clojure, common-lisp, c#"
...
...
spec/benchmark/bulk_generate_spec.rb
deleted
100644 → 0
View file @
aaa72d0f
spec/spec_helper.rb
View file @
d50568f4
...
@@ -35,12 +35,8 @@ def create_test_user(id)
...
@@ -35,12 +35,8 @@ def create_test_user(id)
end
end
def
init_without_subscriptions
def
init_without_subscriptions
Comment
.
delete_all
CommentThread
.
delete_all
[
Comment
,
CommentThread
,
User
,
Notification
,
Subscription
,
Activity
,
Delayed
::
Backend
::
Mongoid
::
Job
].
each
(
&
:delete_all
).
each
(
&
:remove_indexes
).
each
(
&
:create_indexes
)
Content
.
recalculate_all_context_tag_weights!
User
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
Tire
.
index
'comment_threads'
do
delete
end
Tire
.
index
'comment_threads'
do
delete
end
CommentThread
.
create_elasticsearch_index
CommentThread
.
create_elasticsearch_index
...
@@ -108,12 +104,7 @@ def init_without_subscriptions
...
@@ -108,12 +104,7 @@ def init_without_subscriptions
end
end
def
init_with_subscriptions
def
init_with_subscriptions
Comment
.
delete_all
[
Comment
,
CommentThread
,
User
,
Notification
,
Subscription
,
Activity
,
Delayed
::
Backend
::
Mongoid
::
Job
].
each
(
&
:delete_all
).
each
(
&
:remove_indexes
).
each
(
&
:create_indexes
)
CommentThread
.
delete_all
Content
.
recalculate_all_context_tag_weights!
User
.
delete_all
Notification
.
delete_all
Subscription
.
delete_all
Tire
.
index
'comment_threads'
do
delete
end
Tire
.
index
'comment_threads'
do
delete
end
CommentThread
.
create_elasticsearch_index
CommentThread
.
create_elasticsearch_index
...
...
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