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
37d3d437
Commit
37d3d437
authored
Jan 24, 2014
by
Greg Price
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #81 from edx/gprice/active-threads-no-comments
Make retrieving user's active threads faster
parents
5f10609d
1ef2b01c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
66 deletions
+13
-66
api/users.rb
+1
-2
lib/helpers.rb
+0
-13
spec/api/user_spec.rb
+12
-51
No files found.
api/users.rb
View file @
37d3d437
...
...
@@ -42,8 +42,7 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
end
presenter
=
ThreadPresenter
.
new
(
paged_active_threads
.
to_a
,
user
,
params
[
:course_id
])
collection
=
presenter
.
to_hash_array
(
true
)
collection
=
author_contents_only
(
collection
,
user_id
)
collection
=
presenter
.
to_hash_array
()
json_output
=
nil
self
.
class
.
trace_execution_scoped
([
'Custom/get_user_active_threads/json_serialize'
])
do
...
...
lib/helpers.rb
View file @
37d3d437
...
...
@@ -198,18 +198,6 @@ helpers do
end
end
def
author_contents_only
(
contents
,
author_id
)
contents
.
map
do
|
content
|
content
[
'children'
]
=
author_contents_only
(
content
[
'children'
],
author_id
)
if
content
[
'children'
].
length
>
0
or
\
(
content
[
'user_id'
]
==
author_id
and
not
content
[
'anonymous'
]
and
not
content
[
'anonymous_to_peers'
])
content
else
nil
end
end
.
compact
end
def
notifications_by_date_range_and_user_ids
start_date_time
,
end_date_time
,
user_ids
#given a date range and a user, find all of the notifiable content
#key by thread id, and return notification messages for each user
...
...
@@ -301,7 +289,6 @@ helpers do
add_method_tracer
:comment
add_method_tracer
:flag_as_abuse
add_method_tracer
:un_flag_as_abuse
add_method_tracer
:author_contents_only
add_method_tracer
:handle_threads_query
end
spec/api/user_spec.rb
View file @
37d3d437
...
...
@@ -64,30 +64,23 @@ describe "app" do
last_response
.
body
.
should
==
"{}"
end
it
"only returns threads with activity from the specified user"
do
it
"only returns threads with activity from the specified user"
do
@comments
[
"t3 c4"
].
author
=
@users
[
"u100"
]
@comments
[
"t3 c4"
].
save!
rs
=
thread_result
100
,
course_id:
"xyz"
rs
.
length
.
should
==
1
check_thread_result
(
@users
[
"u100"
],
@threads
[
"t0"
],
rs
.
first
,
true
)
rs
.
first
[
"children"
].
length
.
should
==
5
end
it
"does not include anonymous leaves"
do
@comments
[
"t0 c4"
].
anonymous
=
true
@comments
[
"t0 c4"
].
save!
rs
=
thread_result
100
,
course_id:
"xyz"
rs
.
length
.
should
==
1
check_thread_result
(
@users
[
"100"
],
@threads
[
"t0"
],
rs
.
first
,
false
)
rs
.
first
[
"children"
].
length
.
should
==
4
rs
.
length
.
should
==
2
check_thread_result
(
@users
[
"u100"
],
@threads
[
"t3"
],
rs
[
0
],
false
)
check_thread_result
(
@users
[
"u100"
],
@threads
[
"t0"
],
rs
[
1
],
false
)
end
it
"does not include anonymous-to-peers leaves"
do
@comments
[
"t0 c3"
].
anonymous_to_peers
=
true
@comments
[
"t0 c3"
].
save!
it
"does not return threads in which the user has only participated anonymously"
do
@comments
[
"t3 c4"
].
author
=
@users
[
"u100"
]
@comments
[
"t3 c4"
].
anonymous_to_peers
=
true
@comments
[
"t3 c4"
].
save!
rs
=
thread_result
100
,
course_id:
"xyz"
rs
.
length
.
should
==
1
check_thread_result
(
@users
[
"100"
],
@threads
[
"t0"
],
rs
.
first
,
false
)
rs
.
first
[
"children"
].
length
.
should
==
4
end
check_thread_result
(
@users
[
"u100"
],
@threads
[
"t0"
],
rs
.
first
,
false
)
end
it
"only returns threads from the specified course"
do
@threads
.
each
do
|
k
,
v
|
...
...
@@ -113,38 +106,6 @@ describe "app" do
actual_order
.
should
==
expected_order
end
it
"only returns content authored by the specified user, and ancestors of that content"
do
# by default, number of comments returned by u100 would be 5
@comments
[
"t0 c2"
].
author
=
@users
[
"u101"
]
# now 4
make_comment
(
@users
[
"u100"
],
@comments
[
"t0 c2"
],
"should see me"
)
# now 5
make_comment
(
@users
[
"u101"
],
@comments
[
"t0 c2"
],
"should not see me"
)
make_comment
(
@users
[
"u100"
],
@threads
[
"t1"
],
"should see me"
)
# now 6
make_comment
(
@users
[
"u101"
],
@threads
[
"t1"
],
"should not see me"
)
rs
=
thread_result
100
,
course_id:
"xyz"
rs
.
length
.
should
==
2
# the leaf of every subtree in the rs must have author==u100
# and the comment count should match our expectation
expected_comment_count
=
6
@actual_comment_count
=
0
def
check_leaf
(
result
)
if
!
result
[
"children"
]
or
result
[
"children"
].
length
==
0
result
[
"username"
].
should
==
"user100"
@actual_comment_count
+=
1
else
result
[
"children"
].
each
do
|
child
|
check_leaf
(
child
)
end
end
end
rs
.
each
do
|
r
|
check_leaf
(
r
)
end
@actual_comment_count
.
should
==
expected_comment_count
end
# TODO: note the checks on result["num_pages"] are disabled.
# there is a bug in GET "#{APIPREFIX}/users/:user_id/active_threads
# and this value is often wrong.
...
...
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