Commit Graph

8712 Commits

Author SHA1 Message Date
Steve Klabnik
b27f27d38d CHANGELOG for 78d5d6f.
It was pointed out by @giner that the CHANGELOG entry for 78d5d6f868
wasn't included. Here it is.
2012-12-06 10:43:33 -08:00
Josh Susser
d2cc10c200 Oracle needs table to check index existence 2012-12-06 09:38:32 -08:00
Josh Susser
dba022f3a9 convert time to string
why is this a Time to start with?
2012-12-06 09:08:10 -08:00
Josh Susser
cb790703a6 dump schema.rb without :version option 2012-12-05 14:33:49 -08:00
Aaron Patterson
0c692f4d12 Merge branch 'joshsusser-master' into merge
* joshsusser-master:
  style cleanup
  Add migration history to schema.rb dump
  Add metadata to schema_migrations

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/schema.rb
2012-12-05 12:13:49 -08:00
claudiob
019df98875 Replace comments' non-breaking spaces with spaces
Sometimes, on Mac OS X, programmers accidentally press Option+Space
rather than just Space and don’t see the difference. The problem is
that Option+Space writes a non-breaking space (0XA0) rather than a
normal space (0x20).

This commit removes all the non-breaking spaces inadvertently
introduced in the comments of the code.
2012-12-04 22:11:54 -08:00
Rafael Mendonça França
2715c4a19a Merge pull request #8417 from kennyj/fix_8414
Fix #8414. Performance problem with postgresql adapter primary_key function.
2012-12-04 09:25:16 -08:00
kennyj
634d28e6cf Fix #8414. Performance problem with postgresql adapter primary_key function. 2012-12-05 02:19:03 +09:00
Vijay Dev
40e16121c0 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	guides/source/migrations.md
2012-12-04 22:26:16 +05:30
Vijay Dev
b5de0ac6b0 Revert "Add documentation to TransactionIsolationError [ci skip]"
This reverts commit 5ff59704f68d284381606a1b76e4ffcfd73b2cfa.

Reason: Seems dubious and adds less value.

[ci skip]
2012-12-04 21:56:21 +05:30
kennyj
d3f4625aed pg_namespace table isn't used. 2012-12-05 01:22:24 +09:00
Yves Senn
db51704bd9 Do not instantiate intermediate AR objects when eager loading.
Closes #3313
2012-12-04 11:52:08 +01:00
Josh Susser
94ef7b515b style cleanup 2012-12-03 21:26:35 -08:00
Josh Susser
f02d2185eb Add migration history to schema.rb dump 2012-12-02 21:16:32 -08:00
Hendy Tanata
b066210823 Fix typo. 2012-12-03 12:37:45 +08:00
Matthew Robertson
0a178000f5 grammar improvements for increment_counter and decrement_counter docs 2012-12-02 19:40:31 -08:00
Matthew Robertson
43405a75bd increment_counter and decrement_counter can accept and array of ids as an arg 2012-12-02 19:40:19 -08:00
Josh Susser
0a5afa229d Add metadata to schema_migrations
migrated_at: timestamp when migration run
fingerprint: md5 hash of migration source
name: filename without version or extension
2012-12-01 19:41:09 -08:00
Alvaro Pereyra
b1e2d7b968 Cleans and removes 'Examples' tag [ci skip] 2012-12-01 15:35:04 -05:00
Alvaro Pereyra
4940d6d096 Cleans and removes useless 'Examples' tag [ci skip] 2012-12-01 15:19:45 -05:00
Carlos Duclos
9bc16d0da2 update AR::Schema docs [ci skip] 2012-12-01 14:49:57 -05:00
Carlos Antonio da Silva
4eca91243d Remove not used variable warnigns 2012-12-01 17:08:02 -02:00
Florent Guilleux
8dc4041a9b Revert "Remove trailing whitespaces"
This reverts commit 90c887fa7d0c454b7533e208daefc342dea4d5f3.
2012-12-01 13:22:49 -05:00
Florent Guilleux
90c887fa7d Remove trailing whitespaces 2012-12-01 13:20:39 -05:00
Florent Guilleux
5ff59704f6 Add documentation to TransactionIsolationError [ci skip] 2012-12-01 13:17:36 -05:00
Carlos Duclos
a1ffc4a31b remove unneeded Examples tag [ci skip] 2012-12-01 12:53:13 -05:00
Vijay Dev
0181c2da97 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	guides/source/active_record_validations.md
2012-12-01 23:00:47 +05:30
Vijay Dev
9685019c4a copy edits [ci skip] 2012-12-01 22:59:10 +05:30
Florent Guilleux
daab9bba88 Fix Calculations#pluck doc to mention several attributes can be selected [ci skip] 2012-12-01 11:23:02 -05:00
claudiob
20c03e7037 Remove references to AR::Observer from docs
ActiveRecord::Observer was extracted into a separate gem so it
should not be referenced anymore (see https://github.com/rails/rails/commit/ccecab3)
2012-11-30 13:54:03 -08:00
Jon Leighton
64c53d7ce4 Use separate Relation subclasses for each AR class
At present, ActiveRecord::Delegation compiles delegation methods on a
global basis. The compiled methods apply to all subsequent Relation
instances. This creates several problems:

1) After Post.all.recent has been called, User.all.respond_to?(:recent)
   will be true, even if User.all.recent will actually raise an error due
   to no User.recent method existing. (See #8080.)

2) Depending on the AR class, the delegation should do different things.
   For example, if a Post.zip method exists, then Post.all.zip should call
   it. But this will then result in User.zip being called by a subsequent
   User.all.zip, even if User.zip does not exist, when in fact
   User.all.zip should call User.all.to_a.zip. (There are various
   variants of this problem.)

We are creating these compiled delegations in order to avoid method
missing and to avoid repeating logic on each invocation.

One way of handling these issues is to add additional checks in various
places to ensure we're doing the "right thing". However, this makes the
compiled methods signficantly slower. In which case, there's almost no
point in avoiding method_missing at all. (See #8127 for a proposed
solution which takes this approach.)

This is an alternative approach which involves creating a subclass of
ActiveRecord::Relation for each AR class represented. So, with this
patch, Post.all.class != User.all.class. This means that the delegations
are compiled for and only apply to a single AR class. A compiled method
for Post.all will not be invoked from User.all.

This solves the above issues without incurring significant performance
penalties. It's designed to be relatively seamless, however the downside
is a bit of complexity and potentially confusion for a user who thinks
that Post.all and User.all should be instances of the same class.

Benchmark
---------

require 'active_record'
require 'benchmark/ips'

class Post < ActiveRecord::Base
  establish_connection adapter: 'sqlite3', database: ':memory:'
  connection.create_table :posts

  def self.omg
    :omg
  end
end

relation = Post.all

Benchmark.ips do |r|
  r.report('delegation')   { relation.omg }
  r.report('constructing') { Post.all }
end

Before
------

Calculating -------------------------------------
          delegation      4392 i/100ms
        constructing      4780 i/100ms
-------------------------------------------------
          delegation   144235.9 (±27.7%) i/s -     663192 in   5.038075s
        constructing   182015.5 (±21.2%) i/s -     850840 in   5.005364s

After
-----

Calculating -------------------------------------
          delegation      6677 i/100ms
        constructing      6260 i/100ms
-------------------------------------------------
          delegation   166828.2 (±34.2%) i/s -     754501 in   5.001430s
        constructing   116575.5 (±18.6%) i/s -     563400 in   5.036690s

Comments
--------

Bear in mind that the standard deviations in the above are huge, so we
can't compare the numbers too directly. However, we can conclude that
Relation construction has become a little slower (as we'd expect), but
not by a huge huge amount, and we can still construct a large number of
Relations quite quickly.
2012-11-30 14:06:48 +00:00
Jon Leighton
68e4442ec7 Fix memory leak in development mode
Keying these hashes by klass causes reloadable classes to never get
freed. Thanks to @thedarkone for pointing this out in
the comments on 221571beb6b4bb7437989bdefaf421f993ab6002.

This doesn't seem to make a massive difference to performance.

Benchmark
---------

require 'active_record'
require 'benchmark/ips'

class Post < ActiveRecord::Base
  establish_connection adapter: 'sqlite3', database: ':memory:'
end

GC.disable

Benchmark.ips(20) do |r|
  r.report { Post.connection }
end

Before
------

Calculating -------------------------------------
                          5632 i/100ms
-------------------------------------------------
                       218671.0 (±1.9%) i/s -    4364800 in  19.969401s

After
-----

Calculating -------------------------------------
                          8743 i/100ms
-------------------------------------------------
                       206525.9 (±17.8%) i/s -    4039266 in  19.992590s
2012-11-30 11:50:11 +00:00
Jon Leighton
c5bdf6c5ae Mark Relation mutators as :nodoc:
These are for internal use only and cannot be relied on as part of the
public API. See discussion on 8c2c60511beaad05a218e73c4918ab89fb1804f0.
2012-11-30 10:29:46 +00:00
Andrey Deryabin
da67d192d2 Revert "Fix annoy warning, when executing testcase."
This reverts commit a3024f81228d7b3b446408114a5dc2a86870cd35.

REASON: Since warning doesn't exist
2012-11-30 12:07:55 +04:00
Francesco Rodriguez
abdfffa213 add documentation to CollectionProxy #length and #size methods [ci skip] 2012-11-29 12:58:31 -05:00
Francesco Rodriguez
61a7a9f38b add documentation to CollectionProxy#empty? 2012-11-29 12:51:31 -05:00
Jeremy Kemper
f2902eb8e0 Move instantiation responsibilities from Inheritance to Persistence. Have Inheritance#discriminate_class_for_record handle STI lookup duties. 2012-11-29 08:56:09 -07:00
Carlos Antonio da Silva
7ad590d25f User assert_kind_of, invert assert_equal expectations 2012-11-29 09:59:35 -02:00
Jason Rush
89b5b31cc4 Added STI support to init and building associations
Allows you to do BaseClass.new(:type => "SubClass") as well as
parent.children.build(:type => "SubClass") or parent.build_child
to initialize an STI subclass. Ensures that the class name is a
valid class and that it is in the ancestors of the super class
that the association is expecting.
2012-11-29 05:50:34 +00:00
Rafael Mendonça França
ec17f0d352 Add CHANGELOG entries for the observes extraction
[ci skip]
2012-11-29 01:08:36 -02:00
Lucas Mazza
54aed2387c Fix typo in the Observers deprecation message. [ci skip] 2012-11-28 23:08:41 -02:00
Rafael Mendonça França
f862376d16 Gracefully handle upgrading apps with observers
Rather than just raising a NoMethodError when copying the config, this
commit adds a warning message until either the rails-observers gem is
installed or the relevant config options are removed.
2012-11-28 22:49:22 -02:00
Rafael Mendonça França
ccecab3ba9 Remove observers and sweepers
They was extracted from a plugin.

See https://github.com/rails/rails-observers

[Rafael Mendonça França + Steve Klabnik]
2012-11-28 22:46:49 -02:00
Steve Klabnik
22df38ca33 Ensure that associations have a symbol argument.
Fixes #7418.
2012-11-28 13:39:42 -08:00
Rafael Mendonça França
3e965e2144 Fix some indentation in the postgresql_specific_schema 2012-11-28 12:02:11 -02:00
Rafael Mendonça França
f036862c0f Add comment to a table without model.
This table is being used to verify if the :limit options is being
ignored for text and binary columns
2012-11-28 12:02:11 -02:00
Rafael Mendonça França
f3aaf6d7d1 Use assert_nil instead of assert_equal 2012-11-28 12:02:11 -02:00
Carlos Antonio da Silva
daa7b4e2f0 Use "refute" instead of "assert !"
Remove FIXME tag from abstract adapter test.
2012-11-27 21:15:53 -02:00
Carlos Antonio da Silva
462a90565c Remove useless check of AR being defined from teardown fixtures
We are already in the AR namespace, there's no way for it to be
undefined. See the cousin commit 13e72db77063f57c3028a906690d42fb068845bb

Refactor a bit teardown fixtures to avoid two conditionals.
2012-11-27 00:19:26 -02:00
Carlos Antonio da Silva
2cab6a1b5a Merge pull request #8319 from alindeman/typo
Corrects typo in test name [ci skip]
2012-11-26 09:39:06 -08:00