Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create Grape::Request multiple times. #512

Merged
merged 1 commit into from
Nov 24, 2013

Conversation

dblock
Copy link
Member

@dblock dblock commented Nov 21, 2013

For a simple API call we're manufacturing the Grape::Request object many times.

  • lib/grape/middleware/formatter.rb:102:in `format_from_extension' (6 times)
  • lib/grape/endpoint.rb:380:in `new'
  • once if you call .request in the API.

The first one could easily be fixed by storing @request ||= Grape::Request.new, but each middleware and API call would still continue to creating its own request object if it needed one.

This PR attempts to solve that cleanly:

  • Remove Base.request.
  • Decouple the formatter middleware from using a Grape::Request from the base class, use its own.
  • Decouple the oauth2 middleware from using a Grape::Request from the base class, use its own.
  • Assign request, headers and params in endpoint on call.

Will leave this open for a bit for some comments, /cc: @mbleigh.

@dblock
Copy link
Member Author

dblock commented Nov 21, 2013

This is somewhat related to #428, the code here could be even simpler (ie. no need to assign @headers and @params and delegate to request.headers and request.params if Grape::Request could memoize those.

dblock added a commit that referenced this pull request Nov 24, 2013
Don't create Grape::Request multiple times.
@dblock dblock merged commit a401b52 into ruby-grape:master Nov 24, 2013
@dblock dblock deleted the request-globals branch January 3, 2014 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants