switchman 1.9.3 → 1.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 7953977b213e8fd57db12680f2e250db59e6cee0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 86a55be8ebd4c40c7071d0ef65886fd83102a4ce
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b1ccbcf0e7281cd022bf912a7cfc4dc43dc6801c3556e942929ca4bccd9c308feaed966dc84b3321238f263356bee6b23bfa9e177450555d9786405b48e2b04a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 73491652b599c6c693ffd60563aae72a63f84fef8d96c36aa7e3028edc7f0dc2099d30e328d6badc0088988b8a2b210319b8072e6874763cdb824f018e436d85
         
     | 
| 
         @@ -104,22 +104,18 @@ module Switchman 
     | 
|
| 
       104 
104 
     | 
    
         
             
                    end
         
     | 
| 
       105 
105 
     | 
    
         
             
                  end
         
     | 
| 
       106 
106 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
                  def scope_class
         
     | 
| 
       108 
     | 
    
         
            -
                    self.class.base_class
         
     | 
| 
       109 
     | 
    
         
            -
                  end
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
107 
     | 
    
         
             
                  def save(*args)
         
     | 
| 
       112 
108 
     | 
    
         
             
                    @shard_set_in_stone = true
         
     | 
| 
       113 
     | 
    
         
            -
                     
     | 
| 
      
 109 
     | 
    
         
            +
                    self.class.shard(shard, :implicit).scoping { super }
         
     | 
| 
       114 
110 
     | 
    
         
             
                  end
         
     | 
| 
       115 
111 
     | 
    
         | 
| 
       116 
112 
     | 
    
         
             
                  def save!(*args)
         
     | 
| 
       117 
113 
     | 
    
         
             
                    @shard_set_in_stone = true
         
     | 
| 
       118 
     | 
    
         
            -
                     
     | 
| 
      
 114 
     | 
    
         
            +
                    self.class.shard(shard, :implicit).scoping { super }
         
     | 
| 
       119 
115 
     | 
    
         
             
                  end
         
     | 
| 
       120 
116 
     | 
    
         | 
| 
       121 
117 
     | 
    
         
             
                  def destroy
         
     | 
| 
       122 
     | 
    
         
            -
                     
     | 
| 
      
 118 
     | 
    
         
            +
                    self.class.shard(shard, :implicit).scoping { super }
         
     | 
| 
       123 
119 
     | 
    
         
             
                  end
         
     | 
| 
       124 
120 
     | 
    
         | 
| 
       125 
121 
     | 
    
         
             
                  def clone
         
     | 
| 
         @@ -151,6 +147,14 @@ module Switchman 
     | 
|
| 
       151 
147 
     | 
    
         
             
                    @shard_set_in_stone = false
         
     | 
| 
       152 
148 
     | 
    
         
             
                    copy
         
     | 
| 
       153 
149 
     | 
    
         
             
                  end
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                  if ::Rails.version >= '5'
         
     | 
| 
      
 152 
     | 
    
         
            +
                    def quoted_id
         
     | 
| 
      
 153 
     | 
    
         
            +
                      return super unless self.class.sharded_primary_key?
         
     | 
| 
      
 154 
     | 
    
         
            +
                      # do this the Rails 4.2 way, so that if Shard.current != self.shard, the id gets transposed
         
     | 
| 
      
 155 
     | 
    
         
            +
                      self.class.connection.quote(id, column_for_attribute(self.class.primary_key))
         
     | 
| 
      
 156 
     | 
    
         
            +
                    end
         
     | 
| 
      
 157 
     | 
    
         
            +
                  end
         
     | 
| 
       154 
158 
     | 
    
         
             
                end
         
     | 
| 
       155 
159 
     | 
    
         
             
              end
         
     | 
| 
       156 
160 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,79 +1,81 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Switchman
         
     | 
| 
       2 
2 
     | 
    
         
             
              module ActiveRecord
         
     | 
| 
       3 
3 
     | 
    
         
             
                module QueryCache
         
     | 
| 
       4 
     | 
    
         
            -
                   
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                     
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
                  if ::Rails.version < '5.0.1'
         
     | 
| 
      
 5 
     | 
    
         
            +
                    # thread local accessors to replace @query_cache_enabled
         
     | 
| 
      
 6 
     | 
    
         
            +
                    def query_cache
         
     | 
| 
      
 7 
     | 
    
         
            +
                      thread_cache = Thread.current[:query_cache] ||= {}
         
     | 
| 
      
 8 
     | 
    
         
            +
                      thread_cache[self.object_id] ||= Hash.new { |h,sql| h[sql] = {} }
         
     | 
| 
      
 9 
     | 
    
         
            +
                    end
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
                    def query_cache_enabled
         
     | 
| 
      
 12 
     | 
    
         
            +
                      Thread.current[:query_cache_enabled]
         
     | 
| 
      
 13 
     | 
    
         
            +
                    end
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
                    def query_cache_enabled=(value)
         
     | 
| 
      
 16 
     | 
    
         
            +
                      Thread.current[:query_cache_enabled] = value
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
                    # basically wholesale repeat of the methods from the original (see
         
     | 
| 
      
 20 
     | 
    
         
            +
                    # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb),
         
     | 
| 
      
 21 
     | 
    
         
            +
                    # but with self.query_cache_enabled and self.query_cache_enabled= instead
         
     | 
| 
      
 22 
     | 
    
         
            +
                    # of @query_cache_enabled.
         
     | 
| 
       22 
23 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
                    def enable_query_cache!
         
     | 
| 
      
 25 
     | 
    
         
            +
                      self.query_cache_enabled = true
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
       26 
27 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
                    def disable_query_cache!
         
     | 
| 
      
 29 
     | 
    
         
            +
                      self.query_cache_enabled = false
         
     | 
| 
      
 30 
     | 
    
         
            +
                    end
         
     | 
| 
       30 
31 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
                    def cache
         
     | 
| 
      
 33 
     | 
    
         
            +
                      old, self.query_cache_enabled = query_cache_enabled, true
         
     | 
| 
      
 34 
     | 
    
         
            +
                      yield
         
     | 
| 
      
 35 
     | 
    
         
            +
                    ensure
         
     | 
| 
      
 36 
     | 
    
         
            +
                      self.query_cache_enabled = old
         
     | 
| 
      
 37 
     | 
    
         
            +
                      clear_query_cache unless self.query_cache_enabled
         
     | 
| 
      
 38 
     | 
    
         
            +
                    end
         
     | 
| 
       38 
39 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                    def uncached
         
     | 
| 
      
 41 
     | 
    
         
            +
                      old, self.query_cache_enabled = query_cache_enabled, false
         
     | 
| 
      
 42 
     | 
    
         
            +
                      yield
         
     | 
| 
      
 43 
     | 
    
         
            +
                    ensure
         
     | 
| 
      
 44 
     | 
    
         
            +
                      self.query_cache_enabled = old
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
       45 
46 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
                    def clear_query_cache
         
     | 
| 
      
 48 
     | 
    
         
            +
                      Thread.current[:query_cache]&.clear
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
       49 
50 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                    else
         
     | 
| 
       60 
     | 
    
         
            -
                      if ::Rails.version >= '5'
         
     | 
| 
       61 
     | 
    
         
            -
                        super
         
     | 
| 
      
 51 
     | 
    
         
            +
                    def select_all(arel, name = nil, binds = [], preparable: nil)
         
     | 
| 
      
 52 
     | 
    
         
            +
                      if self.query_cache_enabled && !locked?(arel)
         
     | 
| 
      
 53 
     | 
    
         
            +
                        arel, binds = binds_from_relation(arel, binds)
         
     | 
| 
      
 54 
     | 
    
         
            +
                        sql = to_sql(arel, binds)
         
     | 
| 
      
 55 
     | 
    
         
            +
                        if ::Rails.version >= '5'
         
     | 
| 
      
 56 
     | 
    
         
            +
                          cache_sql(sql, binds) { super(sql, name, binds, preparable: preparable) }
         
     | 
| 
      
 57 
     | 
    
         
            +
                        else
         
     | 
| 
      
 58 
     | 
    
         
            +
                          cache_sql(sql, binds) { super(sql, name, binds) }
         
     | 
| 
      
 59 
     | 
    
         
            +
                        end
         
     | 
| 
       62 
60 
     | 
    
         
             
                      else
         
     | 
| 
       63 
     | 
    
         
            -
                         
     | 
| 
      
 61 
     | 
    
         
            +
                        if ::Rails.version >= '5'
         
     | 
| 
      
 62 
     | 
    
         
            +
                          super
         
     | 
| 
      
 63 
     | 
    
         
            +
                        else
         
     | 
| 
      
 64 
     | 
    
         
            +
                          super(arel, name, binds)
         
     | 
| 
      
 65 
     | 
    
         
            +
                        end
         
     | 
| 
       64 
66 
     | 
    
         
             
                      end
         
     | 
| 
       65 
67 
     | 
    
         
             
                    end
         
     | 
| 
       66 
     | 
    
         
            -
                  end
         
     | 
| 
       67 
68 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
      
 69 
     | 
    
         
            +
                    # no reason to define these on the including class directly. the super
         
     | 
| 
      
 70 
     | 
    
         
            +
                    # works just as well from a method on the included module
         
     | 
| 
      
 71 
     | 
    
         
            +
                    [:insert, :update, :delete].each do |method_name|
         
     | 
| 
      
 72 
     | 
    
         
            +
                      class_eval <<-end_code, __FILE__, __LINE__ + 1
         
     | 
| 
      
 73 
     | 
    
         
            +
                        def #{method_name}(*args)
         
     | 
| 
      
 74 
     | 
    
         
            +
                          clear_query_cache if self.query_cache_enabled
         
     | 
| 
      
 75 
     | 
    
         
            +
                          super
         
     | 
| 
      
 76 
     | 
    
         
            +
                        end
         
     | 
| 
      
 77 
     | 
    
         
            +
                      end_code
         
     | 
| 
      
 78 
     | 
    
         
            +
                    end
         
     | 
| 
       77 
79 
     | 
    
         
             
                  end
         
     | 
| 
       78 
80 
     | 
    
         | 
| 
       79 
81 
     | 
    
         
             
                  private
         
     | 
| 
         @@ -10,7 +10,7 @@ module Switchman 
     | 
|
| 
       10 
10 
     | 
    
         
             
              end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
              class ConnectionPoolProxy
         
     | 
| 
       13 
     | 
    
         
            -
                delegate :spec, :connected?, :default_schema, :with_connection,
         
     | 
| 
      
 13 
     | 
    
         
            +
                delegate :spec, :connected?, :default_schema, :with_connection, :query_cache_enabled, :active_connection?,
         
     | 
| 
       14 
14 
     | 
    
         
             
                         :to => :current_pool
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                attr_reader :category, :schema_cache
         
     | 
| 
         @@ -71,7 +71,12 @@ module Switchman 
     | 
|
| 
       71 
71 
     | 
    
         
             
                  end
         
     | 
| 
       72 
72 
     | 
    
         
             
                end
         
     | 
| 
       73 
73 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
                %w{release_connection disconnect! 
     | 
| 
      
 74 
     | 
    
         
            +
                %w{release_connection disconnect!
         
     | 
| 
      
 75 
     | 
    
         
            +
                   clear_reloadable_connections!
         
     | 
| 
      
 76 
     | 
    
         
            +
                   verify_active_connections!
         
     | 
| 
      
 77 
     | 
    
         
            +
                   clear_stale_cached_connections!
         
     | 
| 
      
 78 
     | 
    
         
            +
                   enable_query_cache!
         
     | 
| 
      
 79 
     | 
    
         
            +
                   disable_query_cache! }.each do |method|
         
     | 
| 
       75 
80 
     | 
    
         
             
                  class_eval(<<-EOS)
         
     | 
| 
       76 
81 
     | 
    
         
             
                      def #{method}
         
     | 
| 
       77 
82 
     | 
    
         
             
                        @connection_pools.values.each(&:#{method})
         
     | 
| 
         @@ -126,6 +131,9 @@ module Switchman 
     | 
|
| 
       126 
131 
     | 
    
         | 
| 
       127 
132 
     | 
    
         
             
                  ::ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec).tap do |pool|
         
     | 
| 
       128 
133 
     | 
    
         
             
                    pool.shard = shard
         
     | 
| 
      
 134 
     | 
    
         
            +
                    if ::Rails.version >= '5.0.1'
         
     | 
| 
      
 135 
     | 
    
         
            +
                      pool.enable_query_cache! if !@connection_pools.empty? && @connection_pools.first.last.query_cache_enabled
         
     | 
| 
      
 136 
     | 
    
         
            +
                    end
         
     | 
| 
       129 
137 
     | 
    
         
             
                  end
         
     | 
| 
       130 
138 
     | 
    
         
             
                end
         
     | 
| 
       131 
139 
     | 
    
         
             
              end
         
     | 
    
        data/lib/switchman/engine.rb
    CHANGED
    
    | 
         @@ -124,7 +124,7 @@ module Switchman 
     | 
|
| 
       124 
124 
     | 
    
         
             
                    # we want it to find the definition from
         
     | 
| 
       125 
125 
     | 
    
         
             
                    # ActiveRecord::ConnectionAdapters::DatabaseStatements, not
         
     | 
| 
       126 
126 
     | 
    
         
             
                    # ActiveRecord::ConnectionAdapters::QueryCache
         
     | 
| 
       127 
     | 
    
         
            -
                    ::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all)
         
     | 
| 
      
 127 
     | 
    
         
            +
                    ::ActiveRecord::ConnectionAdapters::QueryCache.send(:remove_method, :select_all) if ::Rails.version < '5.0.1'
         
     | 
| 
       128 
128 
     | 
    
         | 
| 
       129 
129 
     | 
    
         
             
                    ::ActiveRecord::LogSubscriber.prepend(ActiveRecord::LogSubscriber)
         
     | 
| 
       130 
130 
     | 
    
         
             
                    ::ActiveRecord::Reflection::AbstractReflection.include(ActiveRecord::Reflection::AbstractReflection)
         
     | 
    
        data/lib/switchman/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: switchman
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.9. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.9.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Cody Cutrer
         
     | 
| 
         @@ -10,7 +10,7 @@ authors: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
     | 
    
         
            -
            date: 2017- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2017-03-02 00:00:00.000000000 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
16 
     | 
    
         
             
              name: railties
         
     |