As a follow-up to [#40127][], this commit adds a bug fix for nested form
builders (through either `fields_for` or `fields`) incorrectly
constructing a field's `[id]` attribute. To do so, treat the
`@object_name` with higher precedence than the `@object`, since that
will be provided as instance state during construction.
[#40127]: https://github.com/rails/rails/pull/40127
A good part of the complexity was to support the HashLookupTypeMap
subclass that's only used by the Postgres adapter.
In the end they have a similar-ish interface but this inheritance
doesn't help much.
Worse, adapters using `TypeMap` doesn't need extra arguments. By
skipping this unused feature, we can drastically reduce the memory
footprint, as this feature imposed a 320B per entry overhead.
Each type map can use a non trivial amount of memory (over 10KiB
in our app).
Currently each connection build its own type map from scratch, but
except for postgresql which has extension types, all connections
end up with the same maps.
So the more connections you have the more memory it wastes.
By defining the type map statically for MySQL and SQLite3 connections
we save some memory, share caches, and allow that memory to be handled
by Copy on Write for forking setups.
Ref: https://github.com/rails/rails/pull/42355
The justification for `partial_inserts` back in 2012
(144e8691cbfb8bba77f18cfe68d5e7fd48887f5e) was:
> This is more efficient, and also means that it will be safe to remove
> database columns without getting subsequent errors in running app processes
> (so long as the code in those processes doesn't contain any references to the
> removed column).
But since then `ignored_columns` is a much more reliable way to safely remove a
column, and I doubt the reduced query size really help much.
Additionally, `partial_inserts` prevent removing the default value of a column
in a safe way.
Class variables are confusing and can be slow. In this case we were just
using the class variable as a global to implement Fiber-local variables
on top of. Instead we can use Thread#[] directly to store our Fiber-locals.
This reverts commit 1cdee90d385399083596c22343cc46f51283aca3, reversing
changes made to c3a1bfe187d594ed2c2348cc0ae6c5c894368b8e.
We are reverting this because it caused a change in behavior and we need
to discuss how to address that behavior change and find a work around
that doesn't break existing applications.
Follow up to https://github.com/rails/rails/pull/37313
- Adds regression tests
- Logs a warning in cases where assertions are nested in a way that's likely to be confusing
In Rails 7 zeitwerk_enabled? returns true unconditionally. It exists to let 3rd
party code supporting multiple Rails versions check, but we no longer need to use
it internally.
https://github.com/rails/rails/pull/42601 fixed clearing the inverse relation,
but it didn't account for collection associations.
For these, just assigning `nil` isn't possible because we need the record to
remove it from the collection.
So this PR introduce an explicit method for this purpose rather than
reuse `inversed_from(nil)`.