Commit Graph

6816 Commits

Author SHA1 Message Date
Yves Senn
dce4751a74 doc, hide non-public methods form the api docs. [ci skip]
This is a follow up to #25681, specifically this comment:
https://github.com/rails/rails/pull/25681#issuecomment-238294002

The way the thread local variable is stored is an implementation detail
and subject to change. It makes no sense to only generate a reader or
writer as you'd have to know where to read from or where it writes to.
2016-10-20 21:21:55 +02:00
Rafael Mendonça França
b10227728b
Merge pull request #26830 from headius/mask_forking_fsevent_test_on_jruby
Mask forking filesystem event on JRuby.
2016-10-20 10:42:50 -03:00
Aaron Patterson
cd5e4188ee
Merge pull request #26829 from headius/wait_for_events_in_listen_tests
Wait for file events to propagated for slower Listen backends.
2016-10-19 15:00:38 -07:00
Rafael Mendonça França
bd8b50d2e5
Add comment to remove code when we are in Ruby 2.4 2016-10-14 23:57:03 -03:00
Jesús Burgos
e84ed4fd17 Use built-in #transform_values when available.
The methods Hash#transform_values and Hash#transform_values! have been
implemented in Ruby and they'll be available as part of the standard
library.

Here's the link to the discussion in Ruby's issue tracker:
https://bugs.ruby-lang.org/issues/12512

These methods are implemented in C so they're expected to perform
better.
2016-10-14 14:27:27 +02:00
Rafael França
3c8f26ac14 Merge pull request #26531 from y-yagi/remove_unused_benchmark
remove unused require `benchmark`
2016-10-10 22:04:00 -03:00
Matthew Draper
cb0452e9a5 Fixnum and Bignum are deprecated in Ruby trunk
https://bugs.ruby-lang.org/issues/12739
2016-10-08 08:13:11 +10:30
Matthew Draper
0464b728e2 Merge pull request #26359 from maclover7/jm-speed-up-time
Speed up Time.zone.now
2016-10-06 02:35:35 +10:30
Matthew Draper
4d6feef792 Merge pull request #26684 from matthewd/executor-serial
Avoid bumping the class serial when invoking executor
2016-10-05 05:23:48 +10:30
Matthew Draper
6ecb14715e Merge pull request #26686 from matthewd/deprecation-caller
Correct caller tracking in delegated deprecation methods
2016-10-05 05:23:20 +10:30
Matthew Draper
e8b36e7711 Avoid bumping the class serial when invoking executor 2016-10-03 13:35:51 +10:30
Jon Moss
353122c9da Speed up Time.zone.now
@amatsuda, during his RailsConf talk this past year, presented a
benchmark that showed `Time.zone.now` (an Active Support joint)
performing 24.97x slower than Ruby's `Time.now`. Rails master appears to
be a _bit_ faster than that, currently clocking in at 18.25x slower than
`Time.now`. Here's the exact benchmark data for that:

```
Warming up --------------------------------------
            Time.now   127.923k i/100ms
       Time.zone.now    10.275k i/100ms
Calculating -------------------------------------
            Time.now      1.946M (± 5.9%) i/s -      9.722M in   5.010236s
       Time.zone.now    106.625k (± 4.3%) i/s -    534.300k in   5.020343s

Comparison:
            Time.now:  1946220.1 i/s
       Time.zone.now:   106625.5 i/s - 18.25x slower
```

What if I told you we could make `Time.zone.now` _even_ faster? Well,
that's exactly what this patch accomplishes. When creating `ActiveSupport::TimeWithZone`
objects, we try to convert the provided time to be in a UTC format. All
this patch does is, in the method where we convert a provided time to
UTC, check if the provided time is already UTC, and is a `Time` object
and then return early if that is the case, This sidesteps having to continue on,
and create a new `Time` object from scratch. Here's the exact benchmark
data for my patch:

```
Warming up --------------------------------------
            Time.now   124.136k i/100ms
       Time.zone.now    26.260k i/100ms
Calculating -------------------------------------
            Time.now      1.894M (± 6.4%) i/s -      9.434M in   5.000153s
       Time.zone.now    301.654k (± 4.3%) i/s -      1.523M in   5.058328s

Comparison:
            Time.now:  1893958.0 i/s
       Time.zone.now:   301653.7 i/s - 6.28x slower
```

With this patch, we go from `Time.zone.now` being 18.25x slower than
`Time.now` to only being 6.28x slower than `Time.now`. I'd obviously love some
verification on this patch, since these numbers sound pretty interesting... :)

This is the benchmark-ips report I have been using while working on this:

```ruby
require 'benchmark/ips'

Time.zone = 'Eastern Time (US & Canada)'

Benchmark.ips do |x|
  x.report('Time.now') {
    Time.now
  }

  x.report('Time.zone.now') {
    Time.zone.now
  }

  x.compare!
end
```

cc @amatsuda
cc performance folks @tenderlove and @schneems

![Pretty... pretty... pretty good.](https://media.giphy.com/media/bWeR8tA1QV4cM/giphy.gif)
2016-10-02 15:12:46 -04:00
Matthew Draper
62ed56135b Correct caller tracking in delegated deprecation methods 2016-10-03 05:22:28 +10:30
Andrew White
9128ba5cd4 Cache to_time to improve performance when comparing
In #25880 we tried to cache localtime to fix the performance
regression but that proved to be difficult due to the fact that
localtime/getlocal can take a utc_offset argument. We tried
caching based on the argument but since the argument can be nil
sometimes that meant that if the TZ environment variable changed
then the cached value for nil became invalid. By moving the
caching to DateAndTime#compatibility we don't have to worry about
arguments since it doesn't take any.

There is a possible edge condition where preserve_timezone is set
to false and the system timezone changes then it could result in
a cached value being incorrect but the only way to fix this would
be to remove all caching and live with the performance issue.
2016-10-02 17:15:44 +01:00
Andrew White
bd8f0871c2 Revert "Merge pull request #25880 from ryandv/fix_performance_regression_in_timewithzone_to_time"
Turns out trying to cache on localtime with arguments is too hard
so we'll do it on DateAndTime::Compatibility#to_time instead.

This reverts commit 3132fa6b7d9585e04eb44b25b55d298391b040b5, reversing
changes made to 6949f8e5e7dc901d4e04ebab6c975afb33ca44c9.
2016-10-02 17:02:27 +01:00
Andrew White
6c1dac00df Revert "Merge pull request #26677 from tbalthazar/26644"
Turns out trying to cache on localtime with arguments is too hard
so we'll do it on DateAndTime::Compatibility#to_time instead.

This reverts commit 9ce2d1b1a43fc4ef3db59849b7412d30583a4074, reversing
changes made to 53ede1aff2025d4391d0e05ba471fdaf3110a99c.
2016-10-02 17:00:18 +01:00
Andrew White
9ce2d1b1a4 Merge pull request #26677 from tbalthazar/26644
Fix `ActiveSupport::TimeWithZone#localtime`
2016-10-01 21:30:02 +01:00
Thomas Balthazar
607a6c7a9a Fix ActiveSupport::TimeWithZone#localtime
Previously memoization in `localtime` wasn't taking the `utc_offset`
parameter into account when returning a cached value. It now caches the
computed value depending on the `utc_offset` parameter, e.g:

    Time.zone = "US/Eastern"

    t = Time.zone.local(2016,5,2,11)
    # => Mon, 02 May 2016 11:00:00 EDT -04:00

    t.localtime(-7200)
    # => 2016-05-02 13:00:00 -0200

    t.localtime(-3600)
    # => 2016-05-02 14:00:00 -0100
2016-10-01 13:38:43 +02:00
Matthew Draper
871ca21f6a Tighten the backtrace pollution from passing through callbacks
Callbacks are everywhere, so it's better if we can avoid making a mess
of the backtrace just because we've passed through a callback hook.

I'm making no effort to the before/after invocations: those only affect
backtraces while they're running. The calls that matter are the ones
that remain on the call stack after run_callbacks yields: around
callbacks, and internal book-keeping around the before/afters.
2016-09-30 06:57:43 +09:30
Akira Matsuda
b18f8b9d77 Merge pull request #26402 from mtsmfm/remove-dead-constants
Remove dead constants
2016-09-29 18:52:39 +09:00
Jon Moss
c93b80d53d Merge pull request #26654 from Neodelf/activesupport_1
[ci skip] Remove not necessary whitespace
2016-09-28 17:02:22 -04:00
Andrey Molchanov
1ba3ee4dd1 [ci skip] Use class name instead of path to file 2016-09-28 23:31:54 +03:00
Andrey Molchanov
05eb2c0835 [ci skip] Remove not necessary whitespace 2016-09-28 23:24:26 +03:00
yuuji.yaginuma
34a313aa35 fix typo in DateAndTime::Calculations#all_week doc [ci skip]
`Date.week_start` does not exist. `Date.beginning_of_week` seems to be correct.
Ref: #5339
2016-09-27 12:23:52 +09:00
Kasper Timm Hansen
0dfc467587 fffffff, Add code missing in 29f0fbd 2016-09-25 20:38:12 +02:00
Kasper Timm Hansen
29f0fbd5db Revise setting of run_with_rails_extension.
The Rails test runner supports three ways to run tests: directly, via rake, or ruby.

When Running with Ruby ala `ruby -Itest test/models/post_test.rb` our test file would
be evaluated first, requiring `test_helper` and then `active_support/testing/autorun`
that would then require the test file (which it hadn't been before) thus reevaluating
it. This caused exceptions if using Active Support's declarative syntax.

Fix this by shifting around when we set the how we're run to closer mimick the require
order.

If we're running with `bin/rails test` the test command file is run first and we then
set `run_with_rails_extension`, later we hit `active_support/testing/autorun` and do
nothing — because we've been run elsewhere.

If we at this point haven't set `run_with_rails_extension` we've been running with
`ruby` this whole time and thus we set that.

We should always trigger `Minitest.autorun` as it doesn't hurt to call it twice.

Consolidate the two methods into a single one that better brings out the intent of
why they're there.
2016-09-25 20:36:30 +02:00
Thomas Balthazar
76c2553b88 Fix ActiveSupport::TimeWithZone#in
Previously calls to `in` were being sent to the non-DST aware
method `Time#since` via `method_missing`. It is now aliased to
the DST aware `ActiveSupport::TimeWithZone#+` which handles
transitions across DST boundaries, e.g:

    Time.zone = "US/Eastern"

    t = Time.zone.local(2016,11,6,1)
    # => Sun, 06 Nov 2016 01:00:00 EDT -05:00

    t.in(1.hour)
    # => Sun, 06 Nov 2016 01:00:00 EST -05:00
2016-09-24 09:39:51 +02:00
Aaron Patterson
0bc196518a Merge pull request #26563 from knugie/fix_issue_26430
Prevent circular require of proxy_wrappers.rb, Fixes #26430
2016-09-23 11:27:04 -07:00
Vipul A M
3b0da83c81 Merge pull request #26594 from y-yagi/fix_formatting_of_define_callbacks
fix formatting of `define_callbacks` doc [ci skip]
2016-09-23 15:10:46 +05:30
yuuji.yaginuma
508edbc04f fix formatting of define_callbacks doc [ci skip]
Single backticks don't work with rdoc.
2016-09-23 18:37:45 +09:00
Richard Schneeman
bf19c2230d Merge pull request #26524 from y-yagi/add_check_of_argument
add check of argument
2016-09-22 09:29:25 -05:00
Wolfgang Teuber
b355a43f0e Prevent circular require of proxy_wrappers.rb, Fixes #26430 2016-09-21 00:40:48 +02:00
Andrey Molchanov
e1252e073a [ci skip] Fixed commas according to Oxford comma in rdoc and guides 2016-09-17 22:36:13 +03:00
yuuji.yaginuma
77b2e46df4 remove unused require benchmark
`Benchmark` was removed at 4215e9a
2016-09-17 20:15:28 +09:00
yuuji.yaginuma
97544ed177 add check of argument
`#fetch_multi` in case did not cache hit, to write a cache using the block value.
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache.rb#L383..L384

Therefore, block is a need to pass always, I think should check first.
2016-09-17 16:34:38 +09:00
yuuji.yaginuma
5de91258be fix formatting of Cache::Store#fetch [ci skip]
Single backticks don't work with rdoc.
2016-09-17 15:18:06 +09:00
Michael Grosser
a9aed2ac94
improve error message when include assertions fail
assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message

assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
2016-09-16 12:03:37 -07:00
Ryuta Kamizono
3464cd5c28 Fix broken comments indentation caused by rubocop auto-correct [ci skip]
All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772.
But comments was still kept absolute position. This commit aligns
comments with method definitions for consistency.
2016-09-14 18:26:32 +09:00
Ryunosuke Sato
b9e98d62c2 Remove the word "mongrel" from documents
Currently mongrel is not maintained.
And it couldn't be built with any Ruby versions that
supported by Rails.

It is reasonable to remove the word "mongrel" in order to avoid
confusion from newcomer.
2016-09-07 01:59:37 +09:00
Alex Kitchens
fbccae4d19 Fix Remaining Case-In-Assignment Statement Formatting
Recently, the Rails team made an effort to keep the source code consistent, using Ruboco
(bb1ecdcc677bf6e68e0252505509c089619b5b90 and below). Some of the case
statements were missed.

This changes the case statements' formatting and is consistent with changes
in 810dff7c9fa9b2a38eb1560ce0378d760529ee6b and db63406cb007ab3756d2a96d2e0b5d4e777f8231.
2016-09-06 09:34:09 -05:00
Fumiaki MATSUSHIMA
293cdecee3 Remove dead constants
It seems that we forgot to remove some codes on 7ab4775106
2016-09-06 21:58:34 +09:00
yuuji.yaginuma
951353e476 change Class#descendants to public API [ci skip]
`Class#descendants` has already been displayed in Rails guide,
so I think that may be displayed in doc.
http://guides.rubyonrails.org/active_support_core_extensions.html#descendants
2016-09-05 15:11:03 +09:00
Guillermo Iguaran
841bd8994b Merge pull request #26375 from kamipo/remove_blank_else_branch
Remove blank else branch
2016-09-03 11:18:10 -05:00
Ryuta Kamizono
eceabc8355 Remove blank else branch 2016-09-03 13:42:14 +09:00
Ryuta Kamizono
7c70430ce0 Fix broken heredoc indentation caused by rubocop auto-correct
All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772.
But heredocs was still kept absolute position. This commit aligns
heredocs indentation for consistency.
2016-09-03 13:28:46 +09:00
Xavier Noria
810dff7c9f RuboCop is 100% green 🎉 2016-09-02 00:43:33 +02:00
Xavier Noria
bb1ecdcc67 fixes remaining RuboCop issues [Vipul A M, Xavier Noria] 2016-09-01 23:41:49 +02:00
Andrew White
8c402ef425 Cache to_datetime for performance
As demonstrated in #25880 the to_time method converts the utc time
instance to a local time instance which is an expensive operation.
Since to_datetime involves similar expensive operations we should
also cache it to speed up comparison with lots of values.
2016-09-01 13:19:42 +01:00
Vipul A M
79c847892f
Start passing cipher from EncryptedCookieJar since we use it to determine key length 2016-09-01 03:00:10 +05:30
Vipul A M
ae32b69ab9
Follow up of #25602
Since keys are truncated, ruby 2.4 doesn't accept keys greater than their lenghts.
keys of same value but different lenght and greater than key size of cipher, produce the same results
as reproduced at https://gist.github.com/rhenium/b81355fe816dcfae459cc5eadfc4f6f9
Since our default cipher is 'aes-256-cbc', key length for which is 32 bytes, limit the length of key being passed to Encryptor to 32 bytes.
This continues to support backwards compat with any existing signed data, already encrupted and signed with 32+ byte keys.
Also fixes the passing of this value in multiple tests.
2016-09-01 02:53:48 +05:30