1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

39 commits

Author SHA1 Message Date
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
Akira Matsuda
d5ea33b9a0 [Active Record] require => require_relative
This basically reverts 9d4f79d3d3
2017-10-21 22:48:27 +09:00
Kir Shatrov
831be98f9a Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
Xavier Noria
92c29d82eb Merge branch 'master' into require_relative_2017 2017-07-02 13:50:25 -07:00
Matthew Draper
87b3e226d6 Revert "Merge pull request from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Matthew Draper
3420a14590 Merge pull request from kirs/rubocop-frozen-string
Enforce frozen string in Rubocop
2017-07-02 01:11:50 +09:30
Akira Matsuda
9d4f79d3d3 [Active Record] require => require_relative 2017-07-01 18:38:04 +09:00
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Pat Allan
b86e313df5 Make ActiveRecord frozen string literal friendly. 2017-06-20 19:43:21 +10:00
Akira Matsuda
d89238d767 We're not calling hooks here since 9e4c41c903 2016-11-25 22:28:40 +09:00
Xavier Noria
4df2b779dd applies new string literal convention in activerecord/lib
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:26:45 +02:00
Ryuta Kamizono
7d1dc9841c Fix explain logging with binds
`binds` is an array of a query attribute since Active Record 5.0.
2016-07-20 15:26:39 +09:00
Steve
44bf33c959 Fixed typo in comment 2014-07-19 00:20:41 -07:00
Xavier Noria
ef7a48df75 let EXPLAIN use a thread locals registry [John J. Wang & Xavier Noria]
Closes .
2013-04-16 22:46:55 +02:00
Vipul A M
55686dd1be fix typos in AR. lots of them. 2013-03-19 00:04:39 +05:30
kennyj
e9fc2d3397 Remove unused return value, because collecting_queries_for_explain isn't public API. 2013-03-06 00:35:55 +09:00
Yves Senn
d3688e02ca remove AR auto-explain (config.auto_explain_threshold_in_seconds)
We discussed that the auto explain feature is rarely used.
This PR removes only the automatic explain. You can still display
the explain output for any given relation using `ActiveRecord::Relation#explain`.

As a side-effect this should also fix the connection problem during
asset compilation (). The auto explain initializer in the `ActiveRecord::Railtie`
forced a connection.
2013-02-24 20:01:04 +01:00
Blake Smith
50e8613528 Don't run explain on slow queries for database adapters that don't support it 2012-11-26 09:36:04 -06:00
Jon Leighton
9e4c41c903 Remove ActiveRecord::Model
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.
2012-10-26 15:51:02 +01:00
Jeremy Kemper
4ed156336f Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."
This reverts commit 8384683825.
2012-10-20 11:35:16 -07:00
Jon Leighton
8384683825 Get rid of the ActiveRecord::Model::DeprecationProxy thing.
I think it's going to be too much pain to try to transition the
:active_record load hook from executing against Base to executing
against Model.

For example, after Model is included in Base, and modules included in
Model will no longer get added to the ancestors of Base.

So plugins which wish to be compatible with both Model and Base should
use the :active_record_model load hook which executes *before* Base gets
loaded.

In general, ActiveRecord::Model is an advanced feature at the moment and
probably most people will continue to inherit from ActiveRecord::Base
for the time being.
2012-10-19 18:12:54 +01:00
Xavier Noria
5e1b92044c load active_support/core_ext/class/attribute in active_support/rails 2012-08-02 21:59:23 +02:00
Jon Leighton
e030f26ad3 Simplify AR configuration code.
Get rid of ActiveModel::Configuration, make better use of
ActiveSupport::Concern + class_attribute, etc.
2012-06-15 19:15:36 +01:00
Xavier Noria
afcc7cc301 minor comment revision 2012-06-01 16:57:58 +02:00
Akira Matsuda
c1ea574b27 improve readability of AR explain result 2012-06-01 17:05:52 +09:00
Mark Rushakoff
c13d36c95f More using <tt>x</tt> instead of +x+ when the latter renders improperly. 2012-04-27 21:33:56 -07:00
Xavier Noria
f251437415 disable automatic explain if there is no logger [closes ] 2012-01-26 02:50:46 -08:00
Jon Leighton
93c1f11c0a Support configuration on ActiveRecord::Model.
The problem: We need to be able to specify configuration in a way that
can be inherited to models that include ActiveRecord::Model. So it is
no longer sufficient to put 'top level' config on ActiveRecord::Base,
but we do want configuration specified on ActiveRecord::Base and
descendants to continue to work.

So we need something like class_attribute that can be defined on a
module but that is inherited when ActiveRecord::Model is included.

The solution: added ActiveModel::Configuration module which provides a
config_attribute macro. It's a bit specific hence I am not putting this
in Active Support or making it a 'public API' at present.
2011-12-28 18:27:41 +00:00
Jon Leighton
15fbf5b58b auto_explain_threshold_in_seconds should be a global config option so it can be shared between AR::Base and AR::Model 2011-12-24 11:08:16 +00:00
Xavier Noria
0065f37826 AS::Concern is not really needed for AR::Explain 2011-12-16 12:12:05 -08:00
Jon Leighton
ceb33f8493 Split out most of the AR::Base code into separate modules 🍰 2011-12-15 20:45:37 +00:00
Xavier Noria
4e74bd194b moves some auto explain logic to the subscriber [José Valim & Xavier Noria] 2011-12-04 13:53:26 -08:00
Xavier Noria
cfeac38e2b implements a much faster auto EXPLAIN, closes [José Valim & Xavier Noria]
This commit vastly reduces the impact of auto
explain logging when enabled, while keeping
a negligible cost when disabled.

The first implementation was based on the idea
of subscribing to "sql.active_record" when
needed, and unsubscribing once done. This is
the idea behind AR::Relation#explain. Subscribe,
collect, unsubscribe.

But with the current implementation of notifications
unsubscribing is costly, because it wipes an internal
cache and that puts a penalty on the next event.

So we are switching to an approach where a long-running
subscriber is listening. Instead of collecting the
queries with a closure in a dedicated subscriber, now
we setup a thread local.

If the feature is disabled by setting the threshold
to nil, the subscriber will call a method that does
nothing. That's totally cheap.
2011-12-04 11:52:12 -08:00
Xavier Noria
de24ed9f2d removes the convenience instance version of AR::Base.silence_auto_explain
Rationale: As discussed with José and Jon, this convenience
shortcut is not clearly justified and it could let the user
thing the disabled EXPLAINs are related to the model instance
rather than being globally disabled.
2011-12-03 14:26:34 +01:00
Xavier Noria
3a967806ad yield > block.call 2011-12-02 11:44:04 -08:00
Xavier Noria
15dab0d2f5 two small details from the previous patch 2011-12-02 11:29:35 -08:00
Xavier Noria
0be5adaedf implements AR::Base(.|#)silence_auto_explain 2011-12-02 11:16:26 -08:00
Xavier Noria
36cc1f78eb revises some details in the previous explain patch 2011-12-02 09:19:13 -08:00
Xavier Noria
0306f82e0c implements automatic EXPLAIN logging for slow queries 2011-12-02 04:35:43 -08:00