Posts

Showing posts with the label Includes

Optimizing Database Queries in Ruby on Rails: Best Practices and Examples - Part 2

Hi, This is  Shubham Mishra  from India,  this is the part of  Ruby on Rails  exploration journey.  In this post we will discuss about the ruby's some special concepts and I am sure you will get excited to make your hands dirty with those code, so why to wait let's get started... Before jumping over different code snippets lets read some theory first,here are some tips for optimizing Ruby on Rails ActiveRecord queries: Use eager loading: As discussed earlier, eager loading can be used to fetch associated records in a single query, rather than making a separate query for each association. This can greatly reduce the number of database queries and improve performance. Avoid N+1 queries: N+1 queries occur when a query is made to fetch a record, and then additional queries are made for each associated record. This can be avoided by using eager loading, or by preloading associated records using the includes method. Use appropriate indexing: In...

Ruby on Rails: Understanding, Optimizing, and Mastering Database Queries with Preloading, Eager Loading, Includes, and Joins

Hi, This is  Shubham Mishra  from India,  this is the part of  Ruby on Rails  exploration journey.  In this post we will discuss about the ruby's some special concepts and I am sure you will get excited to make your hands dirty with those code, so why to wait let's get started... In this article we will explore best practices to avoid N+1 query issue in ruby on rails and also best practices to make database query optimised. And we also need to keep below stuffs in mind while doing the code review of our peer. Ruby on Rails offers a number of methods for preloading related items in order to get around the N+1 query problem. When the application does his N+1 database queries, the N+1 query problem arises. where N represents the total number of records found. Serious performance problems may result from this, especially when working with huge datasets. Using eager loading, which preloads related objects when the database is requested, is one way to deal wi...