Skip to content

Commit

Permalink
Added method to IM to remove objects by class and id. Then used it to…
Browse files Browse the repository at this point in the history
… remove objects when updating counters.
  • Loading branch information
miloops committed Nov 19, 2010
1 parent 4a0a160 commit 024bc70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/counter_cache.rb
Expand Up @@ -73,6 +73,8 @@ def update_counters(id, counters)
"#{quoted_column} = COALESCE(#{quoted_column}, 0) #{operator} #{value.abs}"
end

IdentityMap.remove_by_id(symbolized_base_class, id) if IdentityMap.enabled?

update_all(updates.join(', '), primary_key => id )
end

Expand Down
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/identity_map.rb
Expand Up @@ -59,6 +59,10 @@ def remove(record)
repository[record.class.symbolized_base_class].delete(record.id)
end

def remove_by_id(symbolized_base_class, id)
repository[symbolized_base_class].delete(id)
end

def clear
repository.clear
end
Expand Down

0 comments on commit 024bc70

Please sign in to comment.