karmi/tire — Issue #155: When search response is extremely large logging takes a long time
Author: redbeard
Created: 2011-11-29 01:11:10+00:00
State: open

This is an edge case which happens when the query response is extremely large due to large document content and the logger level is in debug mode.

Essentially the logger rendering the response content into separate lines takes long enough that it times out the request if originating from a Rails controller.

Tracked down to line 50 in logger.rb,
json.to_s.each_line { |line| content += "# #{line}" } unless json.to_s !~ /\S/

The call to .each_line takes a non-trivial amount of time when the response has hundreds of lines.

Suggested trivial patch:

index d8c0122..a84f6cc 100644
--- a/lib/tire/logger.rb
+++ b/lib/tire/logger.rb
@@ -47,7 +47,8 @@ module Tire
content += " [#{status}]"
content += " (#{took} msec)" if took
content += "\n#\n" unless json.to_s !~ /\S/
- json.to_s.each_line { |line| content += "# #{line}" } unless json.to_s !~ /\S/
+ line_no = 0
+ json.to_s.each_line { |line| content += "# #{line}"; line_no = line_no + 1; break if (line_no > 50) } unless json.to_s !~ /\S/
content += "\n\n"
write content
end