| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
| |
`reflection.join_primary_key`
|
| |
|
|
|
|
|
|
|
|
| |
Since we have `Preloader#preload`, `Preloader::Association#preload` is a
little confusing. And also, since the `preload` method is an abstract
method, it is hard to read where `associated_records_by_owner` is
called. This refactors `Preloader::Association` to ease to read where
`associated_records_by_owner` is called.
|
|
|
|
|
|
|
|
|
| |
given
Related 2b5f5cdd7c1d95716de6a206b6d09ccbb006dc17.
If `reflection.scope` isn't given, `reflection_scope` is always empty
scope. It is unnecessary to merge it.
|
|
|
|
|
|
|
|
|
| |
Related 2b5f5cdd7c1d95716de6a206b6d09ccbb006dc17.
If `through_scope` is empty scope, it is unnecessary to merge it.
And also, comparing relations is a little expensive (will cause
`build_arel`). It is enough to use `empty_scope?` to determine whether
empty scope.
|
|
|
|
| |
`through_scope` is not empty scope if `options[:source_type]` is given.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
`ActiveRecord::Associations::Preloader::Association`.
```
require 'active_record'
require 'benchmark/ips'
ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL'))
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name, :email
t.integer :topic_id
t.timestamps null: false
end
create_table :topics, force: true do |t|
t.string :title
t.timestamps null: false
end
end
attributes = {
name: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
email: 'foobar@email.com'
}
class Topic < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
belongs_to :topic
end
100.times do
User.create!(attributes)
end
users = User.first(50)
100.times do
Topic.create!(title: 'This is a topic', users: users)
end
Benchmark.ips do |x|
x.config(time: 10, warmup: 5)
x.report("preload") do
User.includes(:topic).all.to_a
end
end
```
```
Calculating -------------------------------------
preload 25.000 i/100ms
-------------------------------------------------
preload 251.772 (± 1.2%) i/s - 2.525k
```
```
Calculating -------------------------------------
preload 26.000 i/100ms
-------------------------------------------------
preload 270.392 (± 1.1%) i/s - 2.704k
```
|
|
|
|
|
|
| |
not empty
Because `reflection_scope.values` will create extra new hash.
|
|
|
|
|
| |
If `reflection.scope` isn't given, `reflection_scope` is always
`klass.unscoped`. it is unnecessary to merge it.
|
|
|
|
|
|
|
|
| |
Defined scope treats nil as `all`, but scope in associations isn't so.
If the result of the scope is nil, most features on associations will be
broken. It should treat nil as `all` like defined scope.
Fixes #20823.
|
|
|
|
|
|
|
|
|
|
| |
If `reflection_scope.where_clause` is not empty, `through_scope` should
be joined the source association. But if `values[:references]` in
`reflection_scope` is empty, the source association will not be joined.
It should use `source_reflection.table_name` in that case.
Fixes #22535.
Closes #28763.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Without this fix, preloading `:comments_with_include` will cause the
following error:
```
% bundle exec ruby -w -Itest test/cases/associations/eager_test.rb -n test_eager_with_has_many_through_join_model_with_include
Using sqlite3
Run options: -n test_eager_with_has_many_through_join_model_with_include --seed 1502
E
Error:
EagerAssociationTest#test_eager_with_has_many_through_join_model_with_include:
ActiveRecord::AssociationNotFoundError: Association named 'post' was not found on Post; perhaps you misspelled it?
```
|
|
|
|
|
| |
If `reflection_scope.where_clause` is empty, `scope` isn't changed. So
`scope.eager_loading?` is always false.
|
|
|
|
|
|
| |
Follow up of #29834.
Fixes #30266.
|
|
|
|
|
| |
Since 213796f, array predicate handler supports making binds, so the
preprocess is no longer needed.
|
| |
|
|\
| |
| | |
Make preload query to preparable
|
| |
| |
| |
| |
| |
| |
| | |
Currently preload query cannot be prepared statements even if
`prepared_statements: true` due to array handler in predicate builder
doesn't support making bind params. This makes preload query to
preparable by don't passing array value if possible.
|
|/ |
|
| |
|
|
|
|
| |
These are no longer used since b98668decb9712f26118de57623fd15d7d28646d.
|
|
|
|
|
| |
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
|
| |
|
|\
| |
| | |
Prevent extra `through_scope`
|
| |
| |
| |
| | |
We can reuse `through_scope` for `reset_association`.
|
|/ |
|
|
|
|
| |
Since through association is always loaded by `preloader.preload`.
|
| |
|
|\
| |
| | |
Remove unnecessary `query_scope`
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
If a parent association was accessed in an `after_find` or
`after_initialize` callback, it would always end up loading the
association, and then immediately overwriting the association we just
loaded. If this occurred in a way that the parent's `current_scope` was
set to eager load the child, this would result in an infinite loop and
eventually overflow the stack.
For records that are created with `.new`, we have a mechanism to
perform an action before the callbacks are run. I've introduced the same
code path for records created with `instantiate`, and updated all code
which sets inverse instances on newly loaded associations to use this
block instead.
Fixes #26320.
|
|\ \
| |/
|/|
| | |
Preserve readonly flag only for readonly association
|
| |
| |
| |
| | |
Fixes #24093
|
| | |
|
| | |
|
|/ |
|
|\
| |
| |
| |
| | |
Honour joining model order in `has_many :through` associations when
eager loading
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
association when eager loading.
Previously, eager loading a `has_many :through` association with no
defined order would return the records in the natural order of the
database. Now, these records will be returned in the order that the
joining record is returned, in case there is a defined order there.
|
| |
| |
| |
| |
| | |
This still isn't as separated as I'd like, but it at least moves most of
the burden of alias mapping in one place.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
methyl/fix-includes-for-groupped-association"
This reverts commit 537ac7d6ade61e95f2b70685ff2236b7de965bab, reversing
changes made to 9c9c54abe08d86967efd3dcac1d65158a0ff74ea.
Reason:
The way we preload associations will change the meaning of GROUP BY
operations. This is illustrated in the SQL generated by the added
test (failing on PG):
Association Load:
D, [2015-12-21T12:26:07.169920 #26969] DEBUG -- : Post Load (0.7ms) SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" = $1 GROUP BY posts.id ORDER BY SUM(comments.tags_count) [["author_id", 1]]
Preload:
D, [2015-12-21T12:26:07.128305 #26969] DEBUG -- : Post Load (1.3ms) SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" IN (1, 2, 3) GROUP BY posts.id ORDER BY SUM(comments.tags_count)
|
|\ \
| | |
| | |
| | |
| | |
| | |
| | | |
Pass group values when including association
Conflicts:
activerecord/CHANGELOG.md
|
| | |
| | |
| | |
| | |
| | | |
Fixes problem when added `group()` in association scope was lost
in eager loaded association.
|
|\ \ \
| |/ /
|/| |
| | |
| | | |
yuroyoro/fix_performance_regression_of_preloading_has_many_through_relation
Fix #12537 performance regression when preloading has_many_through association
|
| |/
| |
| |
| |
| | |
For performance, Avoid instantiate CollectionProxy.
Fixes #12537
|
| |
| |
| |
| |
| |
| |
| |
| | |
This is part of a refactoring to make it easier to allow `order` to use
sanitize like just about everything else on relation. The deleted test
doesn't give any reasoning as to why passing `nil` to `order` needs to
be supported, and it's rather nonsensical. I can almost see allowing an
empty string being passed (though I'm tempted to just disallow it...)
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
akihiro17/fix-preload-association""
This reverts commit 5243946017d09afff4d70d273b0fcdfd41a4b22a.
This fixes an issue with the build where tests would fail on mysql and
postgresql due to different ordering.
|
| |
| |
| |
| |
| |
| |
| | |
This reverts commit 6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e, reversing
changes made to ec94f00ba3cf250eb54fc5b7a5e3ed4b90164f34.
This pull request broke the build.
|
| |
| |
| |
| |
| |
| | |
We should call `scope.order!` and set `scope.reordering_value` to `true` if :reordering values are specified
Fixes #21886
|
|\ \
| | |
| | | |
Refactored association preloader for performance
|