Skip to content

Instantly share code, notes, and snippets.

View pawan-yadav's full-sized avatar

Pawan Yadav pawan-yadav

View GitHub Profile
@rmm5t
rmm5t / OUTPUT.md
Last active August 19, 2024 15:05
How to properly introduce a new counter_cache to an existing Rails project.

Fast/efficient approach:

-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id = posts.id)")
   -> 1.3197s

Slow/naïve approach: