Skip to content

Commit

Permalink
Avoid updating timestamp when updating counter_cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Asif S Kalam committed Jul 4, 2012
1 parent b6c67f2 commit 9104ddb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/impressionist/impressionable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def update_impressionist_counter_cache
cache_options = self.class.impressionist_counter_cache_options
column_name = cache_options[:column_name].to_sym
count = cache_options[:unique] ? impressionist_count(:filter => :ip_address) : impressionist_count
update_attribute(column_name, count)
old_count = send(column_name) || 0
self.class.update_counters(id, column_name => (count - old_count))
end

# OLD METHODS - DEPRECATE IN V0.5
Expand Down
7 changes: 7 additions & 0 deletions test_app/spec/models/counter_caching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
@widget.reload
}.should change(@widget, :impressions_count).from(0).to(1)
end

it "should not update the timestamp on the impressable" do
lambda {
@widget.impressions.create(:request_hash => 'abcd1234')
@widget.reload
}.should_not change(@widget, :updated_at)
end
end

end

0 comments on commit 9104ddb

Please sign in to comment.