Skip to content

Commit

Permalink
RC release for Rails 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
malomalo committed Dec 28, 2020
1 parent 4fc3123 commit 684cdec
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion activerecord-cached_at.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
spec.test_files = `git ls-files -- {test}/*`.split("\n")
spec.require_paths = ["lib"]

spec.add_runtime_dependency 'activerecord', '>= 5.2.1'
spec.add_runtime_dependency 'activerecord', '>= 6.1.0'

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
Expand Down
8 changes: 5 additions & 3 deletions lib/cached_at/associations/collection_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ def touch_cached_at(timestamp, method)
cache_column = "#{reflection.inverse_of.name}_cached_at"
ids = [owner.send(reflection.association_primary_key), owner.send("#{reflection.association_primary_key}_before_last_save")].compact.uniq
query = klass.where({ reflection.foreign_key => ids })

if loaded?
target.each { |r| r.send(:write_attribute_without_type_cast, cache_column, timestamp) }
target.each do |record|
record.send(:write_attribute_without_type_cast, cache_column, timestamp)
end
end

if method != :destroy
Expand Down Expand Up @@ -47,7 +49,7 @@ def touch_records_cached_at(records, timestamp)
traverse_relationships(klass, options[:cached_at], query, cache_column, timestamp)
end

def add_to_target(record, skip_callbacks = false, &block)
def add_to_target(record, skip_callbacks: false, replace: false, &block)
value = super
touch_records_cached_at([record], Time.now) if !(instance_variable_defined?(:@caching) && @caching)
value
Expand Down
2 changes: 1 addition & 1 deletion lib/cached_at/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def update_relations_cached_at_from_cached_at(method: nil)
end

def update_relations_cached_at(timestamp: nil, method: nil)
method = instance_variable_defined?(:@new_record_before_save) && @new_record_before_save ? :create : :update if method.nil?
method = @_new_record_before_last_commit ? :create : :update if method.nil?

diff = saved_changes.transform_values(&:first)
return if method == :create && diff.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/cached_at/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CachedAt
VERSION = '6.0.0'
VERSION = '6.1.0.rc1'
end
7 changes: 4 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,20 @@ def initialize(ignore = Regexp.union(self.class.ignored_sql))

def call(name, start, finish, message_id, values)
sql = values[:sql]
binds = " " + values[:binds].map{|v| v.is_a?(ActiveRecord::Relation::QueryAttribute) ? v.value_for_database : v}.inspect

# FIXME: this seems bad. we should probably have a better way to indicate
# the query was cached
return if 'CACHE' == values[:name]

self.class.log_all << sql
self.class.log_all << (sql + binds)
unless ignore =~ sql
if $debugging
puts caller.select { |l| l.starts_with?(File.expand_path('../../lib', __FILE__)) }
puts caller.select { |l| l.start_with?(File.expand_path('../../lib', __FILE__)) }
puts "\n\n"
end
end
self.class.log << sql unless ignore =~ sql
self.class.log << (sql + binds) unless ignore =~ sql
end
end
ActiveSupport::Notifications.subscribe('sql.active_record', SQLLogger.new)
Expand Down

0 comments on commit 684cdec

Please sign in to comment.