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

Feature/remove eager loading #238

Conversation

coorasse
Copy link
Member

Using code from @elabs and continuing on what I wrote here: #171 (comment) that is my suggestion.
Note that I fixed it only for AR4

@@ -65,6 +65,7 @@ def database_records
@model_class.where(nil).merge(override_scope)
elsif @model_class.respond_to?(:where) && @model_class.respond_to?(:joins)
if mergeable_conditions?
puts conditions

Choose a reason for hiding this comment

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

You'll want to remove the outputs in this file :)

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@Senjai
Copy link
Member

Senjai commented Oct 8, 2015

Could we write some more tests to verify the correct sql is being generated? This is a more complex PR and may have some edge cases I may not be aware of. Going to pull it down and review it more thoroughly.

@Senjai Senjai added this to the 3.x milestone Oct 8, 2015
@coorasse
Copy link
Member Author

coorasse commented Oct 8, 2015

Would you prefer to reduce the amount of code and depend directly from this gem? https://github.com/elabs/ar_outer_joins

Is an old gem with just 15 stars so I preferred to include the code directly but we can eventually remove it and add the dependency. what do you think?

@mrloop
Copy link

mrloop commented Oct 28, 2015

Configurable includes In some scenarios I'd like to be able to specify per model what gets included to reduce further sql requests I know I'm going to make when looking at a resources related models.

@mrloop
Copy link

mrloop commented Oct 28, 2015

Ah look somebody has already suggested this #228

@coorasse
Copy link
Member Author

You can specify what to include already with .includes(:table_a, :table_b) directive. Which is even more clear.

@mrloop
Copy link

mrloop commented Oct 28, 2015

@coorasse but I'm loading the resource via load_and_authorize_resource. How do I tell cancan to .includes(:table_a, :table_b) during load_and_authorize_resource find?

@mrloop
Copy link

mrloop commented Oct 28, 2015

Ok, your just getting a scope from load_and_authorize_resource, thanks @coorasse

@coorasse
Copy link
Member Author

coorasse commented Dec 3, 2015

Hello @Senjai. I think this PR brings an important improvement and, at the same time, change in cancancan.
I can rely on this gem https://github.com/elabs/ar_outer_joins in order to avoid writing more tests here.

I already use the following changes in different projects and I had no problems, even in complex ones (https://github.com/coorasse/Airesis/tree/master/app/cancan).

I really think using includes to perform outer_joins is a bad choice and cancancan is taking the responsability of preloading stuff when is not required --> performance problems in case of deep relations.
Let the user preload their stuff and let cancancan just check for permissions.

@derosm2
Copy link

derosm2 commented Dec 17, 2015

+1

@lowjoel
Copy link

lowjoel commented Feb 15, 2016

@coorasse https://github.com/nerde/left_join seems a little newer. Do you want to use that instead?

@Senjai
Copy link
Member

Senjai commented Jun 24, 2016

@coorasse Want to get on a hangout at some point for this one?

@coorasse coorasse changed the base branch from develop to feature/v2 December 11, 2016 15:32
…o feature/remove_eager_loading

# Conflicts:
#	lib/cancan/model_adapters/active_record_3_adapter.rb
@coorasse coorasse changed the base branch from feature/v2 to develop May 18, 2017 09:56
@coorasse coorasse modified the milestones: 3.x, 3.0 May 31, 2017
@kaspernj
Copy link
Contributor

kaspernj commented Sep 9, 2017

+1

@kaspernj
Copy link
Contributor

kaspernj commented Sep 9, 2017

Once the following PR is merged into Rails, it should be possible to just do a .left_outer_joins instead in Rails 5: rails/rails#30410

@aliou
Copy link

aliou commented Oct 19, 2017

Any news on this feature ?

@coorasse coorasse changed the base branch from develop to feature/3.0.0 November 22, 2017 13:17
@coorasse
Copy link
Member Author

I think this will fall in the next Major version (3.0) where I plan to deprecate also AR4. Therefore this PR will be simplified by a lot and rely on left_outer_join by AR5

require "cancan/model_adapters/ar_outer_joins/join"

module ArOuterJoins
def outer_joins(*joins)
Copy link
Contributor

Choose a reason for hiding this comment

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

In Rails 5 we got .left_joins. The duplicate table in this regard was fixed in rails/rails#30410.

Maybe rename this to left_joins and only use if it Rails version is below Rails 5.2?

@bmulholland
Copy link

What's the status of v3.0?

@coorasse
Copy link
Member Author

Closed in favor of #508

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants