Home / Companies / PlanetScale / Blog / Post Details
Content Deep Dive

Solving N+1’s with Rails `exists?` queries

Blog post from PlanetScale

Post Details
Company
Date Published
Author
Mike Coutermarsh
Word Count
395
Company Posts That Month
8
Language
English
Hacker News Points
11
Post removed?
No
Summary

We recently encountered a performance issue in our Rails application due to multiple N+1 .exists? queries on a single API endpoint, specifically when checking if the "data_imports" feature is enabled for a user. This pattern became problematic as we added more beta features, leading to slower API response times. To address this, we preloaded all records and then checked them in memory instead of executing additional queries. By using includes to preload records and implementing a scope that only loads necessary records, we were able to solve the N+1 problem while maintaining performance.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.