Skip to content

Commit

Permalink
Optimize checks to see if an association is eager loadable (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
jturkel committed Nov 5, 2018
1 parent 9b5ba8f commit 12a37ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 3.0.1
- Enable eager loading of associations on destroyed models in all versions of Rails except 5.2.0 since
Rails issue [32375](https://github.com/rails/rails/pull/32375) has been fixed.
- Optimize checks to see if an association is eager loadable.

### 3.0.0
* Drop support for Ruby <= 2.2.
Expand Down
12 changes: 6 additions & 6 deletions lib/goldiloader/active_record_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ def fully_load?

def eager_loadable?
association_info = Goldiloader::AssociationInfo.new(self)
!association_info.limit? &&
association_info.auto_include? &&
!association_info.limit? &&
!association_info.offset? &&
(!association_info.has_one? || !association_info.order?) &&
(!association_info.group? || ::Goldiloader::Compatibility.group_eager_loadable?) &&
(!association_info.from? || ::Goldiloader::Compatibility.from_eager_loadable?) &&
!association_info.instance_dependent? &&
association_info.auto_include? &&
(!owner.destroyed? || ::Goldiloader::Compatibility.destroyed_model_associations_eager_loadable?)
(::Goldiloader::Compatibility.group_eager_loadable? || !association_info.group?) &&
(::Goldiloader::Compatibility.from_eager_loadable? || !association_info.from?) &&
(::Goldiloader::Compatibility.destroyed_model_associations_eager_loadable? || !owner.destroyed?) &&
!association_info.instance_dependent?
end

def load_with_auto_include
Expand Down

0 comments on commit 12a37ea

Please sign in to comment.