Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Commits on Oct 2, 2015
  1. @sgrif

    Build the `AttributeMutationTracker` lazily

    sgrif authored
    For reads, we never need to construct this object. The double `defined?`
    check is to avoid errors in tests
Commits on Sep 24, 2015
  1. @sgrif

    Encapsulate a lot of the logic from `Dirty` in an object

    sgrif authored
    In order to improve the performance of dirty checking, we're going to
    need to duplicate all of the `previous_` methods in Active Model.
    However, these methods are basically the same as their non-previous
    counterparts, but comparing `@original_attributes` to
    `@previous_original_attributes` instead of `@attributes` and
    `@original_attributes`. This will help reduce that duplication.
  2. @sgrif

    Clean up the implementation of AR::Dirty

    sgrif authored
    This moves a bit more of the logic required for dirty checking into the
    attribute objects. I had hoped to remove the `with_value_from_database`
    stuff, but unfortunately just calling `dup` on the attribute objects
    isn't enough, since the values might contain deeply nested data
    structures. I think this can be cleaned up further.
    This makes most dirty checking become lazy, and reduces the number of
    object allocations and amount of CPU time when assigning a value. This
    opens the door (but doesn't quite finish) to improving the performance
    of writes to a place comparable to 4.1
Commits on Jul 24, 2015
  1. @sgrif

    `destroy` shouldn't raise when child associations fail to save

    sgrif authored
    Deep down in the association internals, we're calling `destroy!` rather
    than `destroy` when handling things like `dependent` or autosave
    association callbacks. Unfortunately, due to the structure of the code
    (e.g. it uses callbacks for everything), it's nearly impossible to pass
    whether to call `destroy` or `destroy!` down to where we actually need
    As such, we have to do some legwork to handle this. Since the callbacks
    are what actually raise the exception, we need to rescue it in
    `ActiveRecord::Callbacks`, rather than `ActiveRecord::Persistence` where
    it matters. (As an aside, if this code wasn't so callback heavy, it
    would handling this would likely be as simple as changing `destroy` to
    call `destroy!` instead of the other way around).
    Since we don't want to lose the exception when `destroy!` is called (in
    particular, we don't want the value of the `record` field to change to
    the parent class), we have to do some additional legwork to hold onto it
    where we can use it.
    Again, all of this is ugly and there is definitely a better way to do
    this. However, barring a much more significant re-architecting for what
    I consider to be a reletively minor improvement, I'm willing to take
    this small hit to the flow of this code (begrudgingly).
Commits on Jun 10, 2015
  1. @dcrec1
Commits on May 28, 2015
  1. @rafaelfranca

    Merge pull request #19886 from henders/henders/reload_wipe_query_cache

    rafaelfranca authored
    Cause ActiveRecord::Base::reload to also ignore the QueryCache.
Commits on May 2, 2015
  1. @yuki24

    AR::RecordNotSaved & RecordNotDestroyed should include an error message

    yuki24 authored
    When `!` or `AR::Base.destroy!` is called and an exception
    is raised, the exception doesn't have any error message or has a weird
    message like `#<FailedBulb:0x0000000907b4b8>`. Give a better message so
    we can easily understand why it's failing to save/destroy.
Commits on Apr 28, 2015
  1. @henders
Commits on Apr 27, 2015
  1. @senny
  2. @senny

    Merge pull request #19918 from vngrs/becomes_missing_note_about_sti

    senny authored
    Add note about sti column value to becomes method [ci skip]
  3. @meinac
Commits on Apr 19, 2015
  1. @rafaelfranca

    Use _read_attribute(primary_key) instead of id

    rafaelfranca authored
    This will avoid the indirection of having calling id since we already
    know which is the primary key column.
    Also this will make explicit the behavior since it is not clear that id
    gets the right primary key value and not just the value of the "id"
  2. @meinac

    Raise StaleObjectError if touched object is stale and locking is enabled

    meinac authored
    Fixes #19776
    change test variable names and use more verbose on method
    less verbose
    use _read_attribute instead of send
Commits on Apr 8, 2015
  1. @arthurnn

    Batch touch parent records

    arthurnn authored
    [fixes #18606]
    Make belongs_to use touch over touch_later when running the callbacks.
    Add more tests and small method rename
    Thanks Jeremy for the feedback.
Commits on Mar 2, 2015
  1. @tenderlove

    call `sync_with_transaction_state` inside `persisted?` then check ivars

    tenderlove authored
    calling `sync_with_transaction_state` is not fast, so if we call it
    once, we can improve the performance of the `persisted?` method.  This
    is important because every call to `url_for(model)` will call
    `persisted?`, so we want that to be fast.
    Here is the benchmark:
    require 'active_record'
    ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
    ActiveRecord::Base.connection.instance_eval do
    class Article < ActiveRecord::Base; end
    article =!)
    Benchmark.ips do |x|"persisted?") do
    Before this patch:
    $ bundle exec ruby -rbenchmark/ips persisted.rb
    Calculating -------------------------------------
              persisted?     3.333k i/100ms
              persisted?     51.037k (± 8.2%) i/s -    253.308k
    $ bundle exec ruby -rbenchmark/ips persisted.rb
    Calculating -------------------------------------
              persisted?     7.172k i/100ms
              persisted?    120.730k (± 5.1%) i/s -    602.448k
Commits on Feb 20, 2015
  1. @rafaelfranca

    Merge pull request #16989 from Empact/reload-cache-clear

    rafaelfranca authored
    Isolate access to @associations_cache and @aggregations_cache to the Associations and Aggregations modules, respectively.
  2. @rafaelfranca

    Merge pull request #17139 from mfazekas/fix_becomes_changed_attributes

    rafaelfranca authored
    Always reset changed attributes in becomes
Commits on Feb 18, 2015
  1. @hjoo

    Add `time` option to `#touch`

    hjoo authored
    Fixes #18905. `#touch` now takes time as an option. Setting the option
    saves the record with the updated_at/on attributes set to the current time
    or the time specified. Updated tests and documentation accordingly.
Commits on Feb 4, 2015
  1. @mfazekas

    Always reset changed attributes in becomes

    mfazekas authored
    When ```becomes``` changes @attributes it should also change
    @changed_attributes. Otherwise we'll experience a kind of split head situation
    where attributes are coming from ```self```, but changed_attributes is coming
    from ``````. This affects the inheritance_colmn as it's changed by new
    for example.
    Fixes #16881
Commits on Feb 1, 2015
  1. @tenderlove
Commits on Jan 23, 2015
  1. @mechanicles
Commits on Jan 18, 2015
  1. @prathamesh-sonpatki

    Run SQL only if attribute changed for update_attribute method

    prathamesh-sonpatki authored
     - This is based on #18400 but
       tackling same issue with update_attribute method instead of update method.
Commits on Jan 14, 2015
  1. @sgrif

    Go through normal where logic in destroy

    sgrif authored
    Building the Arel AST, and manipulating the relation manually like this
    is prone to errors and breakage as implementation details change from
    underneath it.
Commits on Jan 2, 2015
  1. @claudiob

    Deprecate `false` as the way to halt AR callbacks

    claudiob authored
    Before this commit, returning `false` in an ActiveRecord `before_` callback
    such as `before_create` would halt the callback chain.
    After this commit, the behavior is deprecated: will still work until
    the next release of Rails but will also display a deprecation warning.
    The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
Commits on Dec 29, 2014
  1. @claudiob

    Add doc for `:touch` option of AR::Base#save

    claudiob authored
    ActiveRecord::Base `save` and `save!` take an option boolean
    `:touch` parameter since #18225 (stems from #18202).
    This commit document that parameter.
    [ci skip]
Commits on Dec 28, 2014
  1. @DanOlson
Commits on Dec 24, 2014
  1. @zzak
Commits on Dec 3, 2014
  1. @senny

    document that `.delete` does work on `#readonly?` records. Closes #11860

    senny authored
    [ci skip]
    This is due to the fact that `.delete` is directly translated to SQL.
    It tries to follow the same rules as `.delete_all` which is not able
    to verify that records are `#readonly?`.
Commits on Nov 28, 2014
  1. @yuki24

    Fix a bug where AR::RecordNotSaved loses error messages

    yuki24 authored
    Since 3e30c5d, it started ignoring the given error message. This commit
    changes the behavior of AR::RecordNotSaved#initialize so that it no
    longer loses the given error message.
Commits on Nov 26, 2014
  1. @recursive-madman

    Add #record attribute to RecordNotFound and RecordDestroyed exceptions.

    recursive-madman authored
    This allows these exceptions to be handled generically in conjunction with RecordInvalid.
Commits on Nov 17, 2014
  1. @sgrif

    Remove the unused second argument to `substitute_at`

    sgrif authored
    Oh hey, we got to remove some code because of that!
Commits on Nov 14, 2014
  1. @sgrif

    Revert "Improve performance of AR object instantiation"

    sgrif authored
    This reverts commit 8fee923.
    This solution sucks, and is hard to actually apply across the board.
    Going to try other solutions
Commits on Nov 7, 2014
  1. @frankywahl

    Print out a meaningful error when ActiveRecord::ReadOnlyRecord is raised

    frankywahl authored
    Currently, there is no messages which get printed out. Convoluted system
    may have hooks that create other objects in which case we only fail with
    no messages. This commit changes this information allowing you to know
    which object is the one that actually raised the error.
Commits on Nov 5, 2014
  1. @sgrif

    Improve performance of AR object instantiation

    sgrif authored
    We introduced a performance hit by adding an additional iteration
    through a model's attributes on creation. We don't actually need the
    values from `Result` to be a hash, we can separate the columns and
    values and zip them up ourself during the iteration that we have to do.
Commits on Sep 28, 2014
  1. @Empact

    Isolate access to @associations_cache and @aggregations cache to the …

    Empact authored
    …Associations and Aggregations modules, respectively.
    This includes replacing the `association_cache` accessor with a more
    limited `association_cached?` accessor and making `clear_association_cache`
    and `clear_aggregation_cache` private.
Something went wrong with that request. Please try again.