Sha256: 834e72d2408f04a649ee73138080c08cc1eec99e7eef08bfcd017bf6fd454f29

Contents?: true

Size: 996 Bytes

Versions: 6

Compression:

Stored size: 996 Bytes

Contents

module Switchman
  module ActiveRecord
    module QueryCache

      private

      def cache_sql(sql, name, binds)
        # have to include the shard id in the cache key because of switching dbs on the same connection
        sql = "#{self.shard.id}::#{sql}"
        @lock.synchronize do
          result =
              if query_cache[sql].key?(binds)
                args = {
                  sql: sql,
                  binds: binds,
                  name: name,
                  connection_id: object_id,
                  cached: true
                }
                args[:type_casted_binds] = -> { type_casted_binds(binds) } if ::Rails.version >= '5.1.5'
                ::ActiveSupport::Notifications.instrument(
                    "sql.active_record",
                    args
                )
                query_cache[sql][binds]
              else
                query_cache[sql][binds] = yield
              end
          result.dup
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
switchman-2.0.1 lib/switchman/active_record/query_cache.rb
switchman-2.0.0 lib/switchman/active_record/query_cache.rb
switchman-1.16.0 lib/switchman/active_record/query_cache.rb
switchman-1.15.2 lib/switchman/active_record/query_cache.rb
switchman-1.15.1 lib/switchman/active_record/query_cache.rb
switchman-1.15.0 lib/switchman/active_record/query_cache.rb