Skip to content

Commit

Permalink
Merge pull request #38 from weeyum/weeyum--use-oj-json-library
Browse files Browse the repository at this point in the history
Use OJ library for json operations
  • Loading branch information
weeyum committed Jul 24, 2017
2 parents ee7bbd3 + e5859bd commit 46ad340
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ gem 'unicorn', '~> 4.8.3'
gem 'unicorn-worker-killer', '~> 0.4.4'
gem 'hash-deep-merge', '~> 0.1.1'
gem 'newrelic_rpm', '~> 3.18.1', group: :newrelic
gem 'oj', '~> 3.3.2'
gem 'stomp', '~> 1.3.2'
gem 'statsd-ruby', '~> 1.2.1'
4 changes: 2 additions & 2 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'json'
opts = JSON.parse( File.read('config.json') )
require 'oj'
opts = Oj.load( File.read('config.json') )

# prepare the logger
require 'logger'
Expand Down
4 changes: 2 additions & 2 deletions events.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

require 'stomp'
require 'oj'

class Events
def initialize(opts)
Expand Down Expand Up @@ -32,7 +32,7 @@ def start
end

def send(data)
@client.publish("/exchange/#{@exchange_name}/#{@routing}", data.to_json, {:persistent => true})
@client.publish("/exchange/#{@exchange_name}/#{@routing}", Oj.dump(data), {:persistent => true})
rescue Exception => e
@log.error "unexpected error publishing to rabbitmq: #{e.inspect}"
raise e
Expand Down
6 changes: 3 additions & 3 deletions optica.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'sinatra/base'
require 'json'
require 'cgi'
require 'oj'

class Optica < Sinatra::Base
configure :production, :development do
Expand Down Expand Up @@ -71,12 +71,12 @@ def get_nodes(request, fields_to_include=nil)

content_type 'application/json', :charset => 'utf-8'
result = {'examined'=>examined, 'returned'=>to_return.count, 'nodes'=>to_return}
return result.to_json
return Oj.dump(result)
end

post '/' do
begin
data = JSON.parse request.body.read
data = Oj.load request.body.read
rescue JSON::ParserError
data = {}
end
Expand Down
6 changes: 3 additions & 3 deletions store.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'zk'
require 'json'
require 'oj'
require 'hash_deep_merge'

class Store
Expand Down Expand Up @@ -137,7 +137,7 @@ def add(node, data)
# deep-merge the old and new data
prev_data = get_node(child)
new_data = prev_data.deep_merge(data)
json_data = new_data.to_json
json_data = Oj.dump(new_data)

@log.debug "writing to zk at #{child} with #{json_data}"

Expand Down Expand Up @@ -196,7 +196,7 @@ def get_node(node)
@zk.get(node)
end
STATSD.time('optica.json.parse') do
JSON.parse(data)
Oj.load(data)
end
rescue ZK::Exceptions::NoNode
@log.info "node #{node} disappeared"
Expand Down

0 comments on commit 46ad340

Please sign in to comment.