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