| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
A common source of bugs and code bloat within Active Record has been the
need for us to maintain the list of bind values separately from the AST
they're associated with. This makes any sort of AST manipulation
incredibly difficult, as any time we want to potentially insert or
remove an AST node, we need to traverse the entire tree to find where
the associated bind parameters are.
With this change, the bind parameters now live on the AST directly.
Active Record does not need to know or care about them until the final
AST traversal for SQL construction. Rather than returning just the SQL,
the Arel collector will now return both the SQL and the bind parameters.
At this point the connection adapter will have all the values that it
had before.
A bit of this code is janky and something I'd like to refactor later. In
particular, I don't like how we're handling associations in the
predicate builder, the special casing of `StatementCache::Substitute` in
`QueryAttribute`, or generally how we're handling bind value replacement
in the statement cache when prepared statements are disabled.
This also mostly reverts #26378, as it moved all the code into a
location that I wanted to delete.
/cc @metaskills @yahonda, this change will affect the adapters
Fixes #29766.
Fixes #29804.
Fixes #26541.
Close #28539.
Close #24769.
Close #26468.
Close #26202.
There are probably other issues/PRs that can be closed because of this
commit, but that's all I could find on the first few pages.
|
|\
| |
| | |
Use frozen-string-literal in ActiveRecord
|
| | |
|
|/
|
|
|
|
|
|
| |
This reverts commit b6ad4052d18e4b29b8a092526c2beef013e2bf4f.
This is not something that the majority of Active Record should be
testing or care about. We should look at having fewer places rely on
these details, not make it easier to rely on them.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
|
| |
|
|
|
|
|
|
|
| |
This regression is caused by d1249c1.
If STI model is defined `default_scope`, `base_rel` is not respected.
I fixed to merge `base_rel` in that case.
|
|
|
|
|
|
| |
".. with __dir__ we can restore order in the Universe." - by @fxn
Related to 5b8738c2df003a96f0e490c43559747618d10f5f
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
We faced a significant performance decrease when we started using STI
without storing full namespaced class name in type column (because of PostgreSQL
length limit for ENUM types).
We realized that the cause of it is the slow STI model instantiation. Problematic
method appears to be `ActiveRecord::Base.compute_type`, which is used to find
the right class for STI model on every instantiation.
It builds an array of candidate types and then iterates through it calling
`safe_constantize` on every type until it finds appropriate constant. So if
desired type isn't the first element in this array there will be at least one
unsuccessful call to `safe_constantize`, which is very expensive, since it's
defined in terms of `begin; rescue; end`.
This commit is an attempt to speed up `compute_type` method simply by caching
results of previous calls.
```ruby
class MyCompany::MyApp::Business::Accounts::Base < ApplicationRecord
self.table_name = 'accounts'
self.store_full_sti_class = false
end
class MyCompany::MyApp::Business::Accounts::Free < Base
end
class MyCompany::MyApp::Business::Accounts::Standard < Base
# patch .compute_type there
end
puts '======================= .compute_type ======================='
Benchmark.ips do |x|
x.report("original method") do
MyCompany::MyApp::Business::Accounts::Free.send :compute_type, 'Free'
end
x.report("with types cached") do
MyCompany::MyApp::Business::Accounts::Standard.send :compute_type, 'Standard'
end
x.compare!
end
```
```
======================= .compute_type =======================
with types cached: 1529019.4 i/s
original method: 2850.2 i/s - 536.46x slower
```
```ruby
5_000.times do |i|
MyCompany::MyApp::Business::Accounts::Standard.create!(name: "standard_#{i}")
end
5_000.times do |i|
MyCompany::MyApp::Business::Accounts::Free.create!(name: "free_#{i}")
end
puts '====================== .limit(100).to_a ======================='
Benchmark.ips do |x|
x.report("without .compute_type patch") do
MyCompany::MyApp::Business::Accounts::Free.limit(100).to_a
end
x.report("with .compute_type patch") do
MyCompany::MyApp::Business::Accounts::Standard.limit(100).to_a
end
x.compare!
end
```
```
====================== .limit(100).to_a =======================
with .compute_type patch: 360.5 i/s
without .compute_type patch: 24.7 i/s - 14.59x slower
```
|
|
|
|
|
|
|
|
| |
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces
Fix all violations in the repository.
|
| |
|
| |
|
|
|
|
|
| |
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
|
|
|
|
|
| |
In this patch, all log-related stuff in `ActiveSupport::Dependencies`
is removed because the logging is no longer useful.
|
|
|
|
|
|
|
|
|
|
| |
The commit which originally added this behavior did not consider that
doing `Subclass.new` does not actually populate the `type` field in the
attributes (though perhaps it should). We simply need to not use the
defaults for STI related things unless we are instantiating the base
class.
Fixes #23285.
|
| |
|
|
|
|
|
|
|
| |
Closes #21986.
This makes it possible to write custom types that define a different
mapping for STI columns.
|
|
|
|
|
|
| |
This will also get the defaults from attribute definitions like:
attribute :type, :string, default: "SomethingElse"
|
|\
| |
| |
| | |
STI cast new instances to `default type` on initialize.
|
|/
|
|
| |
fixes #17121
|
|
|
|
|
|
|
|
| |
These methods are defined in inheritance.rb
* `abstract_class?`
* `descends_from_active_record?`
* `compute_type`
|
|
|
|
|
|
|
| |
This reverts commit 60c9701269f5b412849f1a507df61ba4735914d7, reversing
changes made to 6a25202d9ea3b4a7c9f2d6154b97cf8ba58403db.
Reason: Broken build
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This triggers the JoinDependency work to reflect on the associations
and trigger an error as follows:
ActiveRecord::ConfigurationError: Association named 'account' was
not found on Company; perhaps you misspelled it?
Fix Company.of_first_firm joins association name
Should be `Company.joins(:accounts)` not `Company.joins(:account)`.
Do the same for Client.of_first_firm
|
|
|
|
|
|
|
| |
This can resolve confusing situation when a top level constant exists
but a namespaced version is identified.
Related to #19531.
|
|\
| |
| |
| |
| |
| |
| | |
https://github.com/agrobbin/rails into agrobbin-sti-subclass-from-attributes
Conflicts:
activerecord/CHANGELOG.md
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If your STI class looks like this:
```ruby
class Company < ActiveRecord::Base
self.store_full_sti_class = false
class GoodCo < Company
end
class BadCo < Company
end
end
```
The expectation (which is valid) is that the `type` in the database is saved as
`GoodCo` or `BadCo`. However, another expectation should be that setting `type`
to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That
second expectation is what this should fix.
|
|
|
|
|
|
|
|
|
| |
Make sure that tests do not hardcode the default value.
For example `test_instantiation_doesnt_try_to_require_corresponding_file`
always restored the configuration to `true` regardless of what it's
original value was.
Extract a helper to make the global modification consistent across tests.
|
|
|
|
|
|
|
|
|
|
| |
When ```becomes``` changes @attributes it should also change
@changed_attributes. Otherwise we'll experience a kind of split head situation
where attributes are coming from ```self```, but changed_attributes is coming
from ```klass.new```. This affects the inheritance_colmn as it's changed by new
for example.
Fixes #16881
|
| |
|
|
|
|
|
|
|
|
|
|
| |
This will allow eager type casting to take place as needed. There
doesn't seem to be any particular reason that the `in` statement was
forced for single values, and the commit message where it was introduced
gives no context.
See
https://github.com/rails/rails/commit/d90b4e2615e8048fdeffc6dffe3246704adee01f
|
|
|
|
|
|
|
| |
We added a comparison to "id", and call to `self.class.primary_key` a
*lot*. We also have performance hits from `&block` all over the place.
We skip the check in a new method, in order to avoid breaking the
behavior of `read_attribute`
|
| |
|
|
|
|
|
|
|
|
| |
Follow-Up to https://github.com/rails/rails/pull/14348
Ensure that SQLCounter.clear_log is called after each test.
This is a step to prevent side effects when running tests. This will allow us to run them in random order.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit fixes two regressions introduced in cafe31a078 where
newly created finder methods #second, #third, #forth, and #fifth
caused a NoMethodError error on reload associations and where we
were pulling the wrong element out of cached associations.
Examples:
some_book.authors.reload.second
# Before
# => NoMethodError: undefined method 'first' for nil:NilClass
# After
# => #<Author id: 2, name: "Sally Second", ...>
some_book.first.authors.first
some_book.first.authors.second
# Before
# => #<Author id: 1, name: "Freddy First", ...>
# => #<Author id: 1, name: "Freddy First", ...>
# After
# => #<Author id: 1, name: "Freddy First", ...>
# => #<Author id: 2, name: "Sally Second", ...>
Fixes #13783.
|
|
|
|
|
|
|
| |
The `subclass_from_attrs` method is called even if the column specified by
the `inheritance_column` setting doesn't exist. This prevents setting associations
via the attributes hash if the association name clashes with the value of the setting,
typically `:type`. This worked previously in Rails 3.2.
|
| |
|
| |
|
|
|
|
| |
Related issue: #11939, #12084
|
| |
|
|
|
|
|
| |
These tests should be in inheritance_test.rb since its testing a
feature which is implemented in inheritance.rb
|
|
|
|
|
|
| |
assertion for
https://github.com/rails/rails/blob/ad624345e54bd20802de67b2b5c9ef29ecf5
d5f4/activerecord/lib/active_record/inheritance.rb#L32
|
|
|
|
|
| |
It cannot find subclass because all classes are loaded automatically
when it needs.
|
| |
|
|
|
|
|
|
|
|
| |
Allows you to do BaseClass.new(:type => "SubClass") as well as
parent.children.build(:type => "SubClass") or parent.build_child
to initialize an STI subclass. Ensures that the class name is a
valid class and that it is in the ancestors of the super class
that the association is expecting.
|
|
|
|
|
|
|
|
|
|
| |
In the end I think the pain of implementing this seamlessly was not
worth the gain provided.
The intention was that it would allow plain ruby objects that might not
live in your main application to be subclassed and have persistence
mixed in. But I've decided that the benefit of doing that is not worth
the amount of complexity that the implementation introduced.
|
|
|
|
|
| |
All tests with a custom inheritance_column use the `Vegtable` model.
The field ruby_type on the Company models is no longer needed
|
|
|
|
|
|
| |
previously the tests with and without a custom `inheritance_column`
used the same models. Since the model then has both fields this can lead
to false positives.
|