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

Improve logger & general string concat performance #959

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/tire/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def put_mapping(type, mapping)
end

url = "#{self.url}/#{type}/_mapping"
url += "?#{params.to_param}" unless params.empty?
url << "?#{params.to_param}" unless params.empty?

payload = { type => mapping }.to_json

Expand Down Expand Up @@ -382,7 +382,7 @@ def update(type, id, payload={}, options={})

type = Utils.escape(type)
url = "#{self.url}/#{type}/#{Utils.escape(id)}/_update"
url += "?#{options.to_param}" unless options.keys.empty?
url << "?#{options.to_param}" unless options.keys.empty?
@response = Configuration.client.post url, MultiJson.encode(payload)
MultiJson.decode(@response.body)

Expand Down
20 changes: 10 additions & 10 deletions lib/tire/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def log_request(endpoint, params=nil, curl='')
# curl -X POST ....
#
content = "# #{time}"
content += " [#{endpoint}]"
content += " (#{params.inspect})" if params
content += "\n#\n"
content += curl
content += "\n\n"
content << " [#{endpoint}]"
content << " (#{params.inspect})" if params
content << "\n#\n"
content << curl
content << "\n\n"
write content
end

Expand All @@ -44,11 +44,11 @@ def log_response(status, took=nil, json='')
# }
#
content = "# #{time}"
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/
content += "\n\n"
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/
content << "\n\n"
write content
end

Expand Down
2 changes: 1 addition & 1 deletion test/integration/reindex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ReindexIntegrationTest < Test::Unit::TestCase

should "transform documents with a passed lambda" do
Tire.index('reindex-test').reindex 'reindex-test-new', transform: lambda { |document|
document[:title] += 'UPDATED'
document[:title] << 'UPDATED'
document
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit/logger_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class LoggerTest < Test::Unit::TestCase
# 2011-03-19 11:00:00:000 [200 OK] (4 msec)
#
log;
# log += json.split.map { |line| "# #{line}" }.join("\n")
json.each_line { |line| log += "# #{line}" }
log += "\n\n"
# log << json.split.map { |line| "# #{line}" }.join("\n")
json.each_line { |line| log << "# #{line}" }
log << "\n\n"
@logger.expects(:write).with do |payload|
payload =~ Regexp.new( Regexp.escape('2011-03-19 11:00:00') )
payload =~ Regexp.new( Regexp.escape('[200 OK]') )
Expand Down