Skip to content
This repository was archived by the owner on Jun 30, 2018. It is now read-only.

When search response is extremely large logging takes a long time #155

@redbeard

Description

@redbeard

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions