1. 13 12月, 2013 1 次提交
  2. 04 9月, 2013 1 次提交
    • B
      Deprecate the delegation of Array bang methods in ActiveRecord::Delegation · 1a40be02
      Ben Woosley 提交于
      The primary means of returning results for Array bang methods is to modify
      the array in-place. When you call these methods on a relation, that
      array is created, modified, and then thrown away. Only the secondary
      return value is exposed to the caller.
      
      Removing this delegation is a straight-forward way to reduce user error
      by forcing callers to first explicitly call #to_a in order to expose
      the array to be acted on by the bang method.
      1a40be02
  3. 31 8月, 2013 5 次提交
  4. 24 7月, 2013 2 次提交
  5. 30 4月, 2013 1 次提交
  6. 19 3月, 2013 1 次提交
  7. 25 2月, 2013 1 次提交
    • Y
      remove AR auto-explain (config.auto_explain_threshold_in_seconds) · d3688e02
      Yves Senn 提交于
      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 (#9385). The auto explain initializer in the `ActiveRecord::Railtie`
      forced a connection.
      d3688e02
  8. 07 1月, 2013 1 次提交
  9. 14 12月, 2012 1 次提交
    • T
      Replace some global Hash usages with the new thread safe cache. · 45448a57
      thedarkone 提交于
      Summary of the changes:
       * Add thread_safe gem.
       * Use thread safe cache for digestor caching.
       * Replace manual synchronization with ThreadSafe::Cache in Relation::Delegation.
       * Replace @attribute_method_matchers_cache Hash with ThreadSafe::Cache.
       * Use TS::Cache to avoid the synchronisation overhead on listener retrieval.
       * Replace synchronisation with TS::Cache usage.
       * Use a preallocated array for performance/memory reasons.
       * Update the controllers cache to the new AS::Dependencies::ClassCache API.
         The original @controllers cache no longer makes much sense after @tenderlove's
         changes in 7b6bfe84 and f345e238.
       * Use TS::Cache in the connection pool to avoid locking overhead.
       * Use TS::Cache in ConnectionHandler.
      45448a57
  10. 30 11月, 2012 1 次提交
    • J
      Use separate Relation subclasses for each AR class · 64c53d7c
      Jon Leighton 提交于
      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.
      64c53d7c
  11. 11 11月, 2012 1 次提交
    • J
      Make ActiveRecord::Delegation#method_missing threadsafe · 12d6d3a6
      Jon Leighton 提交于
      Two threads may be in method_missing at the same time. If so, they might
      both try to define the same delegator method.
      
      Such a situation probably wouldn't result in a particularly spectacular
      bug as one method would probably just be overridden by an identical
      method, but it could cause warnings to pop up. (It could be worse if
      method definition is non-atomic in a particular implementation.)
      
      (We will also need this mutex shortly anyway, see #8127.)
      12d6d3a6
  12. 03 8月, 2012 1 次提交
  13. 18 7月, 2012 1 次提交
  14. 10 6月, 2012 1 次提交
  15. 16 12月, 2011 3 次提交