FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Stop Using .any? the Wrong Way in Rails
How-ToSystems

Stop Using .any? the Wrong Way in Rails

via Dev.toPavel Myslik1mo ago

A single block passed to .any? can silently load thousands of records into memory. No warnings. No errors. Just unnecessary objects. And most Rails developers don’t notice it. You’ve probably used both .any? and .exists? in your Rails app without thinking twice. They both answer the same simple question: Is there at least one record? But under the hood, they can behave very differently. In this article, we’ll look at what actually happens when you call each method, when to use which, and how to avoid a common performance trap. The Basics: Same Query, Same Result If you just need to check whether a relation contains any records at all, both .any? and .exists? generate the same efficient query. user . posts . any? # SELECT 1 AS one FROM "posts" WHERE "posts"."user_id" = 1 LIMIT 1 user . posts . exists? # SELECT 1 AS one FROM "posts" WHERE "posts"."user_id" = 1 LIMIT 1 No objects are loaded into memory. No full table scan. Both methods ask the database a simple yes/no question and return

Continue reading on Dev.to

Opens in a new tab

Read Full Article
26 views

Related Articles

The Boring Skills That Make Developers Unstoppable in 2026
How-To

The Boring Skills That Make Developers Unstoppable in 2026

Medium Programming • 4h ago

I Installed This VS Code Extension… and My Code Got Instantly Better
How-To

I Installed This VS Code Extension… and My Code Got Instantly Better

Medium Programming • 5h ago

The Age of Personalized Software
How-To

The Age of Personalized Software

Medium Programming • 7h ago

Automating Checkout Add-On Recommendations in WordPress for WooCommerce
How-To

Automating Checkout Add-On Recommendations in WordPress for WooCommerce

Dev.to • 7h ago

How-To

Start Here: Learning to develop your own way with SCSIC

Medium Programming • 11h ago

Discover More Articles