Commit 2fd437a0 by Robert Raposa Committed by GitHub

Merge pull request #205 from edx/perf/get-thread-without-responses

Add the ability to request a thread without its responses.
parents f051f495 965efede
...@@ -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|
......
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
...@@ -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
......
...@@ -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}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment