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
2fd437a0
Commit
2fd437a0
authored
Sep 07, 2016
by
Robert Raposa
Committed by
GitHub
Sep 07, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #205 from edx/perf/get-thread-without-responses
Add the ability to request a thread without its responses.
parents
f051f495
965efede
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
9 deletions
+18
-9
api/comment_threads.rb
+1
-1
lib/helpers.rb
+4
-7
presenters/thread.rb
+1
-1
spec/api/comment_thread_spec.rb
+12
-0
No files found.
api/comment_threads.rb
View file @
2fd437a0
...
@@ -49,7 +49,7 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
...
@@ -49,7 +49,7 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
else
else
resp_limit
=
nil
resp_limit
=
nil
end
end
presenter
.
to_hash
(
true
,
resp_skip
,
resp_limit
,
bool_recursive
).
to_json
presenter
.
to_hash
(
bool_with_responses
,
resp_skip
,
resp_limit
,
bool_recursive
).
to_json
end
end
put
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
put
"
#{
APIPREFIX
}
/threads/:thread_id"
do
|
thread_id
|
...
...
lib/helpers.rb
View file @
2fd437a0
require
'new_relic/agent/method_tracer'
require
'new_relic/agent/method_tracer'
helpers
do
helpers
do
def
commentable
def
commentable
@commentable
||=
Commentable
.
find
(
params
[
:commentable_id
])
@commentable
||=
Commentable
.
find
(
params
[
:commentable_id
])
end
end
...
@@ -79,7 +78,6 @@ helpers do
...
@@ -79,7 +78,6 @@ helpers do
obj
.
reload
.
to_hash
.
to_json
obj
.
reload
.
to_hash
.
to_json
end
end
def
pin
(
obj
)
def
pin
(
obj
)
raise
ArgumentError
,
t
(
:user_id_is_required
)
unless
user
raise
ArgumentError
,
t
(
:user_id_is_required
)
unless
user
obj
.
pinned
=
true
obj
.
pinned
=
true
...
@@ -94,8 +92,6 @@ helpers do
...
@@ -94,8 +92,6 @@ helpers do
obj
.
reload
.
to_hash
.
to_json
obj
.
reload
.
to_hash
.
to_json
end
end
def
value_to_boolean
(
value
)
def
value_to_boolean
(
value
)
!!
(
value
.
to_s
=~
/^true$/i
)
!!
(
value
.
to_s
=~
/^true$/i
)
end
end
...
@@ -104,6 +100,10 @@ helpers do
...
@@ -104,6 +100,10 @@ helpers do
value_to_boolean
params
[
"recursive"
]
value_to_boolean
params
[
"recursive"
]
end
end
def
bool_with_responses
value_to_boolean
params
[
"with_responses"
]
||
"true"
end
def
bool_mark_as_read
def
bool_mark_as_read
value_to_boolean
params
[
"mark_as_read"
]
value_to_boolean
params
[
"mark_as_read"
]
end
end
...
@@ -142,7 +142,6 @@ helpers do
...
@@ -142,7 +142,6 @@ helpers do
per_page
,
per_page
,
context
=
:course
context
=
:course
)
)
context_threads
=
comment_threads
.
where
({
:context
=>
context
})
context_threads
=
comment_threads
.
where
({
:context
=>
context
})
if
not
group_ids
.
empty?
if
not
group_ids
.
empty?
...
@@ -365,7 +364,6 @@ helpers do
...
@@ -365,7 +364,6 @@ helpers do
end
end
notification_map
.
to_json
notification_map
.
to_json
end
end
def
filter_blocked_content
body
def
filter_blocked_content
body
...
@@ -390,5 +388,4 @@ helpers do
...
@@ -390,5 +388,4 @@ helpers do
add_method_tracer
:flag_as_abuse
add_method_tracer
:flag_as_abuse
add_method_tracer
:un_flag_as_abuse
add_method_tracer
:un_flag_as_abuse
add_method_tracer
:handle_threads_query
add_method_tracer
:handle_threads_query
end
end
presenters/thread.rb
View file @
2fd437a0
...
@@ -23,7 +23,7 @@ class ThreadPresenter
...
@@ -23,7 +23,7 @@ class ThreadPresenter
@is_endorsed
=
is_endorsed
@is_endorsed
=
is_endorsed
end
end
def
to_hash
with_responses
=
false
,
resp_skip
=
0
,
resp_limit
=
nil
,
recursive
=
true
def
to_hash
(
with_responses
=
false
,
resp_skip
=
0
,
resp_limit
=
nil
,
recursive
=
true
)
raise
ArgumentError
unless
resp_skip
>=
0
raise
ArgumentError
unless
resp_skip
>=
0
raise
ArgumentError
unless
resp_limit
.
nil?
or
resp_limit
>=
1
raise
ArgumentError
unless
resp_limit
.
nil?
or
resp_limit
>=
1
h
=
@thread
.
to_hash
h
=
@thread
.
to_hash
...
...
spec/api/comment_thread_spec.rb
View file @
2fd437a0
...
@@ -513,6 +513,18 @@ describe "app" do
...
@@ -513,6 +513,18 @@ describe "app" do
check_thread_result_json
(
nil
,
thread
,
parsed
)
check_thread_result_json
(
nil
,
thread
,
parsed
)
end
end
context
'when requesting the thread for informational purposes'
do
subject
do
get
"/api/v1/threads/
#{
thread
.
id
}
"
,
with_responses:
false
# we're asking for no responses here.
end
it
'should have no children'
do
expect
(
subject
).
to
be_ok
parsed
=
parse
(
subject
.
body
)
expect
(
parsed
).
not_to
include
(
'children'
)
end
end
context
'when marking as read'
do
context
'when marking as read'
do
subject
do
subject
do
get
"/api/v1/threads/
#{
thread
.
id
}
"
,
{
:user_id
=>
thread
.
author
.
id
,
:mark_as_read
=>
true
}
get
"/api/v1/threads/
#{
thread
.
id
}
"
,
{
:user_id
=>
thread
.
author
.
id
,
:mark_as_read
=>
true
}
...
...
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