Repository navigation
Conversation
Previously, OmniAuth::Builder was a subclass of Rack::Builder.
Rack::Builder#call calls #to_app, rebuilding the Rack application on
each request, and, as it says in the Rack::Builder comments, this may
have a negative impact on performance.
This commit changes OmniAuth::Builder from a class to a module and
defines a ::new method that extends a Rack::Builder instance with that
module, instance_evals any block, and returns the value of #to_app, the
built application.
Using OmniAuth::Builder will now only build the application once.
For users who have been subclassing OmniAuth::Builder, a fix would be
subclassing Rack::Builder directly and including OmniAuth::Builder:
class MyBuilder < Rack::Builder
include OmniAuth::Builder
# ...
end
Resolves omniauth#1083.
| def self.new app, &block | ||
| builder = Rack::Builder.new(app).extend(self) | ||
| builder.instance_eval(&block) if block_given? | ||
| builder.to_app | ||
| end |
There was a problem hiding this comment.
Do we need to pass an app in here? Can we default it to nil like Rack::Builder does in internal code?
There was a problem hiding this comment.
Technically, no, but if no @run (in Rack::Builder internals) is defined by the time #to_app is called, an error will be raised, and the only way to add one would be to call #run in the block.
OmniAuth::Builder.new(nil) do
provider :developer
run proc {}
end
If you needed that, maybe we could extract the first two lines to a separate module method (e.g., ::build) that didn't require an argument.
def self.build(app = nil, &block)
builder = Rack::Builder.new(app).extend(self)
builder.instance_eval(&block) if block_given?
builder
end
def self.new(app, &block)
build(app, &block).to_app
end
| module OmniAuth | ||
| class Builder < ::Rack::Builder | ||
| module Builder | ||
| def self.new app, &block |
There was a problem hiding this comment.
| def self.new app, &block | |
| def self.new(app, &block) |
|
Adding the Breaking Change label: this turns |
|
Thanks for tracking this down! You were right about the cause. I fixed it on master in c29ad9b without the breaking change: |
Previously, OmniAuth::Builder was a subclass of Rack::Builder. Rack::Builder#call calls #to_app, rebuilding the Rack application on each request, and, as it says in the Rack::Builder comments, this may have a negative impact on performance.
This commit changes OmniAuth::Builder from a class to a module and defines a ::new method that extends a Rack::Builder instance with that module, instance_evals any block, and returns the value of #to_app, the built application.
Using OmniAuth::Builder will now only build the application once.
For users who have been subclassing OmniAuth::Builder, a fix would be subclassing Rack::Builder directly and including OmniAuth::Builder:
Resolves #1083.