Commit Graph

53779 Commits

Author SHA1 Message Date
Kevin Deisz
3e3f3563b8 Allow rake:stats to account for rake tasks 2015-10-19 10:36:30 -04:00
Arthur Nogueira Neves
dd2c94aea6 Merge pull request #21988 from y-yagi/remove_useless_method
remove useless method
2015-10-18 11:46:04 -04:00
Eileen M. Uchitelle
c2ed6bfab2 Merge pull request #21989 from imtayadeway/guides/active-model-basics
[ci skip] Improve readability in active model basics guide
2015-10-18 10:46:13 -04:00
Tim Wade
3c0ae9da87
[ci skip] Improve readability in active model basics guide
* adds/removes a few words
* removes an unnecessary comma
2015-10-18 07:35:54 -07:00
yuuji.yaginuma
93d99c55bd remove useless method
`images` method has been deleted in 2bc4856, `create_images_directory` does nothing.
2015-10-18 15:41:07 +09:00
Rafael Mendonça França
6c36c369be Revert "Move the handling of supported arguments to where"
This reverts commit 4d8f62dcfa0a5157b3facbd71f75fc6639636347.

Reason: This broke the build. Please recommit again when it is green.
2015-10-17 19:40:10 -03:00
Yves Senn
bae2292d8f Merge pull request #21982 from yui-knk/test_suppress_warning
Suppress warnings of `assigned but unused variable`
2015-10-17 16:44:16 +02:00
Richard Schneeman
a5e1bc813b Merge pull request #21980 from maratgaliev/timezones_fix
Use "rake time:zones:all" instead of "rake -D time" [ci skip]
2015-10-17 08:38:10 -05:00
yui-knk
3973a48307 Suppress warnings of assigned but unused variable 2015-10-17 17:16:16 +09:00
Marat Galiev
706850a443 Use "rake time:zones:all" instead of "rake -D time" [ci skip] 2015-10-17 09:17:42 +03:00
schneems
101821410b [ci skip] Add backend queue starting documentation
If you can't start your queue, you won't process much. This change adds external links to the Queue backends that have Active Job specific docs.
2015-10-16 18:24:58 -05:00
Sean Griffin
4d8f62dcfa Move the handling of supported arguments to where
`WhereClauseFactory` handles all other branches based on argument types,
so the code fits more naturally here, and it's just where the
responsibility belongs.
2015-10-16 09:51:47 -07:00
Matthew Draper
833aef438d Merge pull request #21953 from bdunne/fix_dep_warn
Fix deprecation warning messages on deprecate_methods
2015-10-17 03:17:21 +10:30
Sean Griffin
cd4575f98c Merge pull request #21944 from jwworth/issue-20473
where raises ArgumentError on unsupported argument types
2015-10-16 09:25:39 -07:00
Jake Worth
7663376f07 where raises ArgumentError on unsupported types.
[#20473]
2015-10-16 09:23:15 -05:00
Yves Senn
b3656076d6 Merge pull request #21969 from ignatiusreza/remove_readonly_option_doc
Remove mentioned of 'readonly' options in doc for HABTM [ci skip]
2015-10-16 10:32:09 +02:00
Ignatius Reza
15f7519361 [ci skip] readonly options has been removed 2015-10-16 16:52:19 +09:00
Aaron Patterson
960de47f0e drop array allocations when iterating over the hash
`each_with_object` allocates an array for each kv pair.  Switching to
the slightly more verbose but less allocatey `each_pair` eliminates
array allocations.  Eliminating this allocation returns AR objects to
have constant array allocations regardless of the number of columns the
object has.

Here is test code:

```ruby
require 'active_record'

class Topic < ActiveRecord::Base
end

20.times do |i|
  Process.waitpid fork {
    ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'

    ActiveRecord::Base.connection.instance_eval do
      create_table(:topics) do |t|
        t.string   :title, limit: 250
        t.string   :author_name
        t.string   :author_email_address
        t.string   :parent_title
        t.string   :type
        t.string   :group
        i.times do |j|
          t.string :"aaa#{j}"
        end
        t.timestamps null: true
      end
    end

    ObjectSpace::AllocationTracer.setup(%i{type})

    Topic.create title: "aaron" # heat cache

    result = ObjectSpace::AllocationTracer.trace do
      10.times do |i|
        Topic.create title: "aaron #{i}"
      end
    end

    puts "#{Topic.columns.length},#{(result.find { |k,v| k.first == :T_ARRAY }.last.first / 10)}"
  }
end
```

Before this commit:

```
9,166
10,167
11,168
12,169
13,170
14,171
15,172
16,173
17,174
18,175
19,176
20,177
21,178
22,179
23,180
24,181
25,182
26,183
27,184
28,185
```

After:

```
9,157
10,157
11,157
12,157
13,157
14,157
15,157
16,157
17,157
18,157
19,157
20,157
21,157
22,157
23,157
24,157
25,157
26,157
27,157
28,157
```

Left side is the number of columns, right is the number of allocations
2015-10-15 14:44:28 -07:00
Rafael Mendonça França
3b61027092 Merge pull request #21966 from AnnaErshova/dbreset-edit
Clarifies db can be set up from structure.sql as well as from schema.rb
2015-10-15 18:37:19 -03:00
Anna Ershova
5cde56e173 Update active_record_migrations.md
Add 'db/'; corrects structure.rb to structure.sql
2015-10-15 16:37:11 -04:00
Aaron Patterson
3253185b36 make string allocation constant regardless of column count
deep_dup'ing a hash will dup the keys as well as the values.  Since
string keys from the source hash will be frozen, and the dup'd objects
are immediately dup'd and frozen on insert in to the hash, the end user
will only ever see two frozen strings.  Since the strings are immutable,
this commit just cheats a little and reuses the immutable strings.

Just to reiterate, before this commit, deep duping a hash that looks
like this: `{ "foo" => "bar" }` will generate two new instances of
"foo". One is created when `deep_dup` is called on "foo", and the other
is created when the newly allocated "foo" string is inserted in to the
hash.  The user never sees the intermediate "foo", and both copies of
"foo" that the user *can* access will be frozen, so in this case we just
reuse the existing frozen key.

The upshot is that after this change, string allocations on AR
allocations become constant regardless of the number of columns the
model has.

```ruby
require 'active_record'

class Topic < ActiveRecord::Base
end

20.times do |i|
  Process.waitpid fork {
    ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'

    ActiveRecord::Base.connection.instance_eval do
      create_table(:topics) do |t|
        t.string   :title, limit: 250
        t.string   :author_name
        t.string   :author_email_address
        t.string   :parent_title
        t.string   :type
        t.string   :group
        i.times do |j|
          t.integer :"aaa#{j}"
        end
        t.timestamps null: true
      end
    end

    ObjectSpace::AllocationTracer.setup(%i{type})

    Topic.create title: "aaron" # heat cache

    result = ObjectSpace::AllocationTracer.trace do
      10.times do |i|
        Topic.create title: "aaron #{i}"
      end
    end

    puts "#{Topic.columns.length},#{(result.find { |k,v| k.first == :T_STRING }.last.first / 10)}"
  }
end
```

If you run the above script before this commit, the output looks like
this:

```
[aaron@TC rails (master)]$ be ruby -rallocation_tracer test.rb
9,105
10,107
11,109
12,111
13,113
14,115
15,117
16,119
17,121
18,123
19,125
20,127
21,129
22,131
23,133
24,135
25,137
26,139
27,141
28,143
```

The left column is the number of methods, the right column is the number
of string allocations.

Running against this commit, the output is:

```
[aaron@TC rails (master)]$ be ruby -rallocation_tracer test.rb
9,87
10,87
11,87
12,87
13,87
14,87
15,87
16,87
17,87
18,87
19,87
20,87
21,87
22,87
23,87
24,87
25,87
26,87
27,87
28,87
```

As you can see, there is now only a constant number of strings
allocated, regardless of the number of columns the model has.
2015-10-15 13:33:42 -07:00
Andrew White
3acc590d50 Merge pull request #21946 from davidcelis/fix-time-zone-utc-predicate
Expand support for ActiveSupport::TimeWithZone#utc?
2015-10-15 18:51:04 +01:00
Sean Griffin
d6919c524a All strings returned by ImmutableString should be frozen
I seriously don't even know why we handle booleans, but those strings
should technically be frozen. Additionally, we don't need to actually
check the class in the mutable string type, since the `cast_value`
function will always return a string.
2015-10-15 09:55:30 -07:00
Sean Griffin
34321e4a43 Add an immutable string type to opt out of string duping
This type adds an escape hatch to apps for which string duping causes
unacceptable memory growth. The reason we are duping them is in order to
detect mutation, which was a feature added to 4.2 in #15674. The string
type was modified to support this behavior in #15788.

Memory growth is really only a concern for string types, as it's the
only mutable type where the act of coersion does not create a new object
regardless (as we're usually returning an object of a different class).

I do feel strongly that if we are going to support detecting mutation,
we should do it universally for any type which is mutable. While it is
less common and ideomatic to mutate strings than arrays or hashes, there
shouldn't be rules or gotchas to understanding our behavior.

However, I also appreciate that for apps which are using a lot of string
columns, this would increase the number of allocations by a large
factor. To ensure that we keep our contract, if you'd like to opt out of
mutation detection on strings, you'll also be option out of mutation of
those strings.

I'm not completely married to the thought that strings coming out of
this actually need to be frozen -- and I think the name is correct
either way, as the purpose of this is to provide a string type which
does not detect mutation.

In the new implementation, I'm only overriding `cast_value`. I did not
port over the duping in `serialize`. I cannot think of a reason we'd
need to dup the string there, and the tests pass without it.
Unfortunately that line was introduced at a time where I was not nearly
as good about writing my commit messages, so I have no context as to
why I added it. Thanks past Sean. You are a jerk.
2015-10-15 09:50:37 -07:00
David Celis
8e847dcde8 Expand support for ActiveSupport::TimeWithZone#utc?
Currently, ActiveSupport::TimeWithZone#utc? simply runs a check to see
if the linked ActiveSupport::TimeZone's name is "UTC". This will only
return true for ActiveSupport::TimeZone["UTC"], but not for time zones
such as "Etc/UTC", "Etc/Universal", or other time zones that are aliases
for UTC. Interestingly enough, ActiveSupport::TimeWithZone#utc? is also
aliased as #gmt? but will return false for the "GMT" timezone (along
with other TZInfo aliases for GMT).

Instead of running a simple check on the TimeZone name, we can rely on
the underlying TZInfo::TimezonePeriod and TZInfo::TimezoneOffset which
keep a record of of the offset's abbreviated name. The possibilities
here for UTC time zones are `:UTC`, `:UCT`, and `:GMT`.

Signed-off-by: David <me@davidcel.is>
2015-10-15 09:25:34 -07:00
Sean Griffin
de92b06bca Merge pull request #21964 from Drenmi/enhancement/update-deprecation-message
Better deprecation warning for `ActiveRecord::Relation#update`
2015-10-15 08:09:18 -07:00
AnnaErshova
0166adcee8 Clarifies db can be set up from structure.sql also
I added that *structure.sql* file can be used when *db:reset* is run.

*db:reset* tasks states *db:reset* loads database from *db/schema.rb*
or *db/structure.sql* depending on the configuration (although
*db/schema.rb* is the default), hence the change.
2015-10-15 09:36:57 -04:00
Ted Johansson
b901a49473 Add deprecation warning to ActiveRecord::Relation#update
When passing an instance of `ActiveRecord::Base` to `#update`, it would
internally call `#find`, resulting in a misleading deprecation warning.

This change gives this deprecated use of `#update` its own, meaningful
warning.
2015-10-15 17:00:28 +08:00
Aaron Patterson
b6cf69ebcb freeze the column name to drop string allocations in dirty checks
Dirty checking keeps a hash where the keys are the column name and the
value is a dup of the value from the database[1].  This hash is kept for
every AR object, which means that we dup every column name for every AR
object that does dirty checking.  Freezing the column name prevents the
column name from being duped and reduced overall string allocations.

Here is a benchmark to demonstrate:

```ruby
require 'active_record'

class Topic < ActiveRecord::Base
end

20.times do |i|
  Process.waitpid fork {
    ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'

    ActiveRecord::Base.connection.instance_eval do
      create_table(:topics) do |t|
        t.string   :title, limit: 250
        t.string   :author_name
        t.string   :author_email_address
        t.string   :parent_title
        t.string   :type
        t.string   :group
        i.times do |j|
          t.string :"aaa#{j}"
        end
        t.timestamps null: true
      end
    end

    ObjectSpace::AllocationTracer.setup(%i{type})

    Topic.create title: "aaron" # heat cache

    result = ObjectSpace::AllocationTracer.trace do
      10.times do |i|
        Topic.create title: "aaron #{i}"
      end
    end

    puts "#{Topic.columns.length},#{(result.find { |k,v| k.first == :T_STRING }.last.first / 10)}"
  }
end
```

1. 3ad381c3f8/activerecord/lib/active_record/attribute_set/builder.rb (L102)
2015-10-14 18:06:56 -07:00
Arthur Nogueira Neves
3ad381c3f8 Merge pull request #21961 from Gaurav2728/migration_class_methods_nodoc
migrations Class methods have nodoc, fix it for API [ci skip]
2015-10-14 14:18:23 -04:00
Gaurav Sharma
d68514c168 migrations Class methods have nodoc, fix it for API [ci skip] 2015-10-14 23:44:12 +05:30
Yves Senn
428d47adfe applies new doc guidelines to Active Record.
The focus of this change is to make the API more accessible.
References to method and classes should be linked to make it easy to
navigate around.

This patch makes exzessiv use of `rdoc-ref:` to provide more readable
docs. This makes it possible to document `ActiveRecord::Base#save` even
though the method is within a separate module
`ActiveRecord::Persistence`. The goal here is to bring the API closer to
the actual code that you would write.

This commit only deals with Active Record. The other gems will be
updated accordingly but in different commits. The pass through Active
Record is not completely finished yet. A follow up commit will change
the spots I haven't yet had the time to update.

/cc @fxn
2015-10-14 17:40:00 +02:00
Yves Senn
809fd2b273 fix RDoc markup in ConnectionPool. [ci skip] 2015-10-14 17:02:45 +02:00
Yves Senn
715d9bd4a1 add missing :nodoc: to AR::Callbacks::ClassMethods. [ci skip] 2015-10-14 16:27:31 +02:00
Yves Senn
8c49fc45be add missing :nodoc: for AutosaveAssociation::ClassMethods [ci skip] 2015-10-14 15:30:13 +02:00
Yves Senn
801371abee fix broken RDoc markup. Use <tt> instead of +. [ci skip] 2015-10-14 13:58:33 +02:00
Brandon Dunne
6c98fbd9c3 Fix bug where custom deprecators are not used.
Add tests for ActiveSupport::Deprecation.deprecate_methods
Modify ActiveSupport::Testing::Deprecation to allow a custom deprecator
Leverage ActiveSupport::Testing::Deprecation assert_deprecated
Update documentation for ActiveSupport::Deprecation.deprecate_methods

Use cases:
Using the default deprecator => "removed from Rails X.Y"
Passing a custom deprecator in the options hash => "removed from MyGem next-release"
Deprecating methods directly from custom deprecator => "removed from MyGem next-release"
2015-10-14 07:49:39 -04:00
Yves Senn
31af8c90b6 fix RDoc list markup in DatabaseTasks. [ci skip] 2015-10-14 11:15:40 +02:00
Yves Senn
215e128ddc add missing :nodoc: to ActiveRecord::Scoping. [ci skip] 2015-10-14 09:45:56 +02:00
Arthur Nogueira Neves
7776bde55a Merge pull request #21635 from sideshowcoder/ar_type_docs_fix
Documentation ActiveRecord Attributes API code fix
2015-10-13 21:50:27 -04:00
Arthur Nogueira Neves
2145701cdd Merge pull request #20908 from y-yagi/generate_application_job_inside_engine
add application_job.rb to template of mountable engine
2015-10-13 21:47:29 -04:00
Matthew Draper
c672586b8d Merge pull request #21954 from xtian/patch-1
Fix formatting of ActiveRecord PostgreSQL guide.
2015-10-14 08:27:24 +10:30
Christian Wesselhoeft
0d34b550a4 Fix formatting of ActiveRecord PostgreSQL guide. 2015-10-13 14:50:19 -06:00
Jeremy Daer
9d05430c95 Merge pull request #19135 from yuki24/access-control-support
Add basic support for access control headers to ActionDispatch::Static
2015-10-13 11:16:50 -07:00
Matthew Draper
8e7a3b0563 Merge pull request #21952 from headius/only_one_module_for_deprecation
Only prepend a single module when defining deprecation wrappers.
2015-10-14 03:33:13 +10:30
Charles Oliver Nutter
d29f7fbb10 Only prepend a single module when defining deprecation wrappers.
I could not find any reason why each method got its own prepended
module here, and all tests appear to pass with my change.
2015-10-13 11:16:49 -05:00
Yves Senn
de732e0015 private def breaks RDoc. Move meathod to preserve the docs.
The rdoc parser seems to trip on the `private def` construct.
Public methods following a method defined with `private def` are not
visible inside the module docs but are appended to the top-most module.

For example the method `ActiveRecord::QueryMethods#distinct` was listed
under `ActiveRecord#distinct`.

/cc @sgrif
2015-10-13 15:05:39 +02:00
Yves Senn
718468e1c9 docs, :nodoc: FromClause, QueryAttribute and WhereClauseFactory.
[ci skip]
2015-10-13 14:28:55 +02:00
Yves Senn
f94bf50d35 docs, add missing :nodoc: for Associations::Builder`. [ci skip]
This class is only used internally. We should keep it out of public
documentation. This patch adds nodoc for
`ActiveRecord::Associations::Builder` and everything nested within.
2015-10-13 14:23:24 +02:00
Yves Senn
ba185c6467 nodoc ActiveRecord::ForeignAssociation. [ci skip] 2015-10-13 13:51:24 +02:00