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

[AutoLoad] Autoload Fixes #1904

Merged
merged 9 commits into from
Sep 6, 2019
Merged

[AutoLoad] Autoload Fixes #1904

merged 9 commits into from
Sep 6, 2019

Conversation

myxoh
Copy link
Member

@myxoh myxoh commented Sep 3, 2019

Partially addresses the issues raises on: #1902

The way it does so is it allows a method compile! that makes a large percentage of the work to warm up the API on load time.

More work is needed before the API is 100% warmed up.


Taking suggestions as to how best to test this

@myxoh myxoh changed the title [AutoLoad] Autoload Fixes [AutoLoad][WIP] Autoload Fixes Sep 3, 2019
@myxoh myxoh changed the title [AutoLoad][WIP] Autoload Fixes [AutoLoad] Autoload Fixes Sep 3, 2019
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

README.md Outdated Show resolved Hide resolved
if never_mounted?
base_instance
else
mounted_instances.first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be all instances and the method to return an array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. I can't remember why this should ever return one of the mounted instances, as you probably want to always be interacting with rack on a predictable instance. I'll have to see what happens if I have this always be the base_instance

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so this change was initially introduced in: https://github.com/ruby-grape/grape/pull/1893/files
The reason why this is needed is that we used to support - before remounting was introduced - the ability to pre-mount the API you will run in a namespace (and I was maintaing backwards compatibility).

Basically you are allowed to do

class ToBeMountedinRack < Grape::API
  get 'endpoint'
end

class Namespace < Grape::API
  namespace 'namespace' do 
    mount ToBeMountedinRack
   end
end

run ToBeMountedinRack

And the expectation is that you will be able to get /namespace/endpoint
I am not sure I want to maintain this behaviour forever, as it doesn't really play nicely with re-mounting an endpoint and I don't find it very sensible (I would find it sensible to run Namespace if you want the above behavour, rather than mounting ToBeMountedinRack)

Nonetheless, I don't think this is the appropiate PR to introduce this change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. We can deprecate this separately.

lib/grape/api/instance.rb Outdated Show resolved Hide resolved
@dblock
Copy link
Member

dblock commented Sep 5, 2019

Ok, I'm good with this. Let's add a test? Something that calls compile! explicitly?

@dblock dblock merged commit 45b1288 into ruby-grape:master Sep 6, 2019
@dblock
Copy link
Member

dblock commented Sep 6, 2019

I merged this.


it 'compiles the instance for rack!' do
stubbed_object = double(:instance_for_rack)
allow(app).to receive(:instance_for_rack) { stubbed_object }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@myxoh I am curious about the purpose of this test case. It seems to test nothing?

basjanssen pushed a commit to basjanssen/grape that referenced this pull request Feb 28, 2020
* [Autoload] allows all bits of Grape to be autoloaded

* [AutoLoad] creates a compile! method to pre load an API class

* [AutoLoad] Addresses rubocop rules, and adds a readme line

* [AutoLoad] Adds changes to changelog

* Addresses issues with danger

* Makes sure the check happens inside the Mutex

* Syntax on the README

* [AutoLoad] does not take the lock to try to compile is an instance is already present

* [AutoLoad] Tests the new methods compile! and instance_for_rack
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.

None yet

3 participants