This fixes the indentation of the example code of the first bullet
point. The "Learn more" link was moved to the bottom of the bullet point,
similar to the other bullet points.
Previously, Rails::BacktraceCleaner was both lazily required and
instantiated. While it would end up being loaded during initialization
for apps that use Active Record (due to active_record.backtrace_cleaner
initializer), it would not be loaded until the first request for those
that don't.
The solution is similar to daff36c, however ::Rails is not currently
in the list of eager_load_namespaces. Therefore simply requiring it
seems like the easiest solution.
The removed comment indicating the lazy require is necessary due to load
order dates back to the addition of Rails::BacktraceCleaner in f42c77f.
This predates the integration of Bundler and reorganization of framework
loading, so it is no longer accurate.
It sounds like a default timeout of 1 second can sometimes not be enough.
In normal operations, this should be fine (will result in a cache miss),
but in these tests, we always expect the cache to return the value, hence doing this change for these tests only.
Co-authored-by: Matthew Draper <matthew@trebex.net>
In #46612, a check was added to only attempt metadata extraction if the
message looks like a JSON object (i.e. starts with "{"), thus avoiding
an unnecessary JSON parse and possible exception.
This commit extends the check to only attempt metadata extraction if the
message looks like a metadata wrapper object (i.e. has the "_rails"
key). This avoids an unnecessary JSON parse of JSON object messages
that don't have metadata.
**Benchmark**
```ruby
require "benchmark/ips"
require "active_support/all"
verifier = ActiveSupport::MessageVerifier.new("secret", serializer: JSON)
message_100 = verifier.generate({ content: "x" * 100 })
message_1m = verifier.generate({ content: "x" * 1_000_000 })
Benchmark.ips do |x|
x.report("100 chars") do
verifier.verify(message_100)
end
x.report("1m chars") do
verifier.verify(message_1m)
end
end
```
**Before**
```
Warming up --------------------------------------
100 chars 2.803k i/100ms
1m chars 6.000 i/100ms
Calculating -------------------------------------
100 chars 27.762k (± 1.6%) i/s - 140.150k in 5.049649s
1m chars 83.516 (±16.8%) i/s - 402.000 in 5.037269s
```
**After**
```
Warming up --------------------------------------
100 chars 3.360k i/100ms
1m chars 9.000 i/100ms
Calculating -------------------------------------
100 chars 33.480k (± 1.7%) i/s - 168.000k in 5.019311s
1m chars 113.373 (±15.0%) i/s - 549.000 in 5.023443s
```
`ActiveRecord::Base::normalizes` declares a normalization for one or
more attributes. The normalization is applied when the attribute is
assigned or updated, and the normalized value will be persisted to the
database. The normalization is also applied to the corresponding
keyword argument of finder methods. This allows a record to be created
and later queried using unnormalized values. For example:
```ruby
class User < ActiveRecord::Base
normalizes :email, with: -> email { email.strip.downcase }
end
user = User.create(email: " CRUISE-CONTROL@EXAMPLE.COM\n")
user.email # => "cruise-control@example.com"
user = User.find_by(email: "\tCRUISE-CONTROL@EXAMPLE.COM ")
user.email # => "cruise-control@example.com"
user.email_before_type_cast # => "cruise-control@example.com"
User.exists?(email: "\tCRUISE-CONTROL@EXAMPLE.COM ") # => true
User.exists?(["email = ?", "\tCRUISE-CONTROL@EXAMPLE.COM "]) # => false
```
* Add Rails.env.local?
So many checks against Rails.env is whether we're running test or development, so combine into just one.
* Add CHANGELOG
* Prevent 'local' from being used as an environment name
Now that we have it as a combined predicate for dev + test.
* Add CMD and refactor ENTRYPOINT
The CMD will run by default when you run the container without supplying
any arguments but you can choose to overwrite this at runtime by
doing: docker container run -it myapp rails c
The ENTRYPOINT will only create or migrate the database when the default
CMD is invoked. If you choose to run a different command such as the
rails console or a background worker process the db:prepare command
will not run.
* Remove extra space from ENTRYPOINT comment