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
c2364402
Commit
c2364402
authored
Sep 04, 2012
by
David Ormsbee
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2 from rll/dave/tuning
Performance tuning
parents
9b188b87
c8204217
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
16 deletions
+20
-16
api/search.rb
+4
-7
models/comment.rb
+2
-0
models/comment_thread.rb
+2
-0
models/subscription.rb
+2
-0
models/user.rb
+10
-9
No files found.
api/search.rb
View file @
c2364402
...
...
@@ -70,15 +70,12 @@ get "#{APIPREFIX}/search/threads/recent_active" do
query_params
[
"commentable_id"
]
=
params
[
"commentable_id"
]
if
params
[
"commentable_id"
]
comment_threads
=
if
follower_id
User
.
find
(
follower_id
).
subscribed_threads
.
select
do
|
thread
|
thread
.
last_activity_at
>=
from_time
and
\
query_params
.
to_a
.
map
{
|
query
|
thread
[
query
.
first
]
==
query
.
last
}.
all?
end
User
.
find
(
follower_id
).
subscribed_threads
else
CommentThread
.
all
.
where
(
query_params
.
merge
(
:last_activity_at
=>
{:
$gte
=>
from_time
}))
CommentThread
.
all
end
comment_threads
.
to_a
.
sort
{
|
x
,
y
|
y
.
last_activity_at
<=>
x
.
last_activity_at
}[
0
..
4
]
.
map
(
&
:to_hash
).
to_json
comment_threads
.
where
(
query_params
.
merge
(
:last_activity_at
=>
{:
$gte
=>
from_time
})).
order_by
(
:last_activity_at
.
desc
).
limit
(
5
).
to_a
.
map
(
&
:to_hash
).
to_json
end
...
...
@@ -86,7 +83,7 @@ get "#{APIPREFIX}/search/tags/trending" do
query_params
=
{}
query_params
[
"course_id"
]
=
params
[
"course_id"
]
if
params
[
"course_id"
]
query_params
[
"commentable_id"
]
=
params
[
"commentable_id"
]
if
params
[
"commentable_id"
]
CommentThread
.
all
.
where
(
query_params
).
to_a
CommentThread
.
where
(
query_params
).
only
(
:tags_array
).
to_a
.
map
(
&
:tags_array
).
flatten
.
group_by
{
|
x
|
x
}
.
map
{
|
k
,
v
|
[
k
,
v
.
count
]}
.
sort_by
{
|
x
|
-
x
.
last
}[
0
..
4
]
...
...
models/comment.rb
View file @
c2364402
...
...
@@ -15,6 +15,8 @@ class Comment < Content
field
:anonymous
,
type:
Boolean
,
default:
false
field
:at_position_list
,
type:
Array
,
default:
[]
index
({
author_id:
1
,
course_id:
1
})
belongs_to
:comment_thread
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
index:
true
...
...
models/comment_thread.rb
View file @
c2364402
...
...
@@ -21,6 +21,8 @@ class CommentThread < Content
field
:at_position_list
,
type:
Array
,
default:
[]
field
:last_activity_at
,
type:
Time
index
({
author_id:
1
,
course_id:
1
})
include
Tire
::
Model
::
Search
include
Tire
::
Model
::
Callbacks
...
...
models/subscription.rb
View file @
c2364402
...
...
@@ -7,6 +7,8 @@ class Subscription
field
:source_type
,
type:
String
index
({
subscriber_id:
1
,
source_id:
1
,
source_type:
1
})
index
({
subscriber_id:
1
,
source_type:
1
})
index
({
subscriber_id:
1
})
def
to_hash
as_document
.
slice
(
*
%w[subscriber_id source_id source_type]
)
...
...
models/user.rb
View file @
c2364402
...
...
@@ -31,23 +31,23 @@ class User
end
def
subscribed_thread_ids
subscriptions_as_subscriber
.
where
(
source_type:
"CommentThread"
).
map
(
&
:source_id
)
Subscription
.
where
(
subscriber_id:
id
.
to_s
,
source_type:
"CommentThread"
).
only
(
:source_id
).
map
(
&
:source_id
)
end
def
subscribed_commentable_ids
subscriptions_as_subscriber
.
where
(
source_type:
"Commentable"
).
map
(
&
:source_id
)
subscriptions_as_subscriber
.
where
(
source_type:
"Commentable"
).
only
(
:source_id
).
map
(
&
:source_id
)
end
def
subscribed_user_ids
subscriptions_as_subscriber
.
where
(
source_type:
"User"
).
map
(
&
:source_id
)
subscriptions_as_subscriber
.
where
(
source_type:
"User"
).
only
(
:source_id
).
map
(
&
:source_id
)
end
def
subscribed_threads
subscribed_thread_ids
.
map
{
|
id
|
CommentThread
.
find
(
id
)}
CommentThread
.
where
(
:id
.
in
=>
subscribed_thread_ids
)
end
def
subscribed_commentables
subscribed_commentable_ids
.
map
{
|
id
|
Commentable
.
find
(
id
)}
Commentable
.
find
(
*
subscribed_commentable_ids
).
only
(
:id
).
map
(
&
:id
)
end
def
subscribed_users
...
...
@@ -60,15 +60,16 @@ class User
hash
=
hash
.
merge
(
"subscribed_thread_ids"
=>
subscribed_thread_ids
,
"subscribed_commentable_ids"
=>
subscribed_commentable_ids
,
"subscribed_user_ids"
=>
subscribed_user_ids
,
"follower_ids"
=>
subscriptions_as_source
.
map
(
&
:subscriber_id
),
"follower_ids"
=>
subscriptions_as_source
.
only
(
:subscriber_id
).
map
(
&
:subscriber_id
),
"id"
=>
id
,
"upvoted_ids"
=>
upvoted_ids
,
"downvoted_ids"
=>
downvoted_ids
,
"default_sort_key"
=>
default_sort_key
)
"default_sort_key"
=>
default_sort_key
)
end
if
params
[
:course_id
]
hash
=
hash
.
merge
(
"threads_count"
=>
comment_threads
.
where
(
course_id:
params
[
:course_id
]).
count
,
"comments_count"
=>
comments
.
where
(
course_id:
params
[
:course_id
]).
count
,
hash
=
hash
.
merge
(
"threads_count"
=>
CommentThread
.
where
(
user_id:
id
,
course_id:
params
[
:course_id
]).
count
,
"comments_count"
=>
Comment
.
where
(
user_id:
id
,
course_id:
params
[
:course_id
]).
count
)
end
hash
...
...
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