Skip to content

Commit

Permalink
Merge pull request ruby-grape#831 from dblock/remove-logging-value
Browse files Browse the repository at this point in the history
Remove logging value, improve nested loading performance.
  • Loading branch information
dblock committed Dec 1, 2014
2 parents 7b3f055 + aeb2d4a commit 98d5960
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 55 deletions.
1 change: 0 additions & 1 deletion lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ module Versioner
end

module Util
autoload :LoggingValue, 'grape/util/logging_value'
autoload :InheritableValues, 'grape/util/inheritable_values'
autoload :StackableValues, 'grape/util/stackable_values'
autoload :InheritableSetting, 'grape/util/inheritable_setting'
Expand Down
14 changes: 2 additions & 12 deletions lib/grape/util/inheritable_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class InheritableValues

def initialize(inherited_values = {})
self.inherited_values = inherited_values
self.new_values = LoggingValue.new
self.new_values = {}
end

def [](name)
Expand Down Expand Up @@ -44,17 +44,7 @@ def initialize_copy(other)
protected

def values
result = LoggingValue.new

@inherited_values.keys.each_with_object(result) do |key, res|
begin
res[key] = @inherited_values[key].clone
rescue
res[key] = @inherited_values[key]
end
end

result.merge(@new_values)
@inherited_values.merge(@new_values)
end
end
end
Expand Down
40 changes: 0 additions & 40 deletions lib/grape/util/logging_value.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/grape/util/stackable_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class StackableValues

def initialize(inherited_values = {})
@inherited_values = inherited_values
@new_values = LoggingValue.new
@new_values = {}
@froozen_values = {}
end

Expand All @@ -35,7 +35,7 @@ def keys

def to_hash
keys.each_with_object({}) do |key, result|
result[key] = self[key].dup
result[key] = self[key]
end
end

Expand Down
44 changes: 44 additions & 0 deletions spec/grape/loading_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'spec_helper'

describe Grape::API do
let(:jobs_api) {
Class.new(Grape::API) do
namespace :one do
namespace :two do
namespace :three do
get :one do
end
get :two do
end
end
end
end
end
}

let(:combined_api) {
JobsApi = jobs_api
Class.new(Grape::API) do
version :v1, using: :accept_version_header, cascade: true
mount JobsApi
end
}

subject {
CombinedApi = combined_api
Class.new(Grape::API) do
format :json
mount CombinedApi => '/'
end
}

def app
subject
end

it 'execute first request in reasonable time' do
started = Time.now
get '/mount1/nested/test_method'
expect(Time.now - started).to be < 5
end
end

0 comments on commit 98d5960

Please sign in to comment.