Fix n+1 queries on Rails
An ebook to help you go from "Please help me with my n+1 problem" to be one of those that can help the team.
Read moreAn ebook to help you go from "Please help me with my n+1 problem" to be one of those that can help the team.
Read moreN+1 queries are not always a problem, but I have seen that most of the n+1 queries that are really a problem are when we need to fetch data to compute something.
Here I will try to share some examples of posible expensive computations candidates to...
Read moreThere are many tools that can help you detect n+1 queries in different ways.
This is a little reference of some of those tools:
You don’t need to use all of them, but is good to know that they exists and how they can help you.
Imagine that you want to truncate a filename, but you want to keep showing the extension of the file. Like “A big file name that…awesome.pdf”. How would you do it?
Imagine that you are building a custom CMS. Within the form to edit an Article
, you need to have two buttons: a normal “Save” button and a new “Save and publish” button. And maybe, additionally, you will need a third button to delete the article.
Imagine that you have a form to update a record (let’s say a product record) and inside the form, you are showing a list of images, and each image needs a button to remove it. You tried to use button_to but it doesn’t work because in html you can have...
Read moreIf you want to add images to a record but you don’t want to use a JavaScript plugin or write any custom JavaScript, you can use a regular file field, Active Storage, and vanilla Rails.
If you want to add many attachments to a record using just a file field, but you don’t want to remove the previous images from the record on every update, like in the following code:
When saving computed values in the database in your rails app, you must be aware that is possible to find unexpected errors in the result thanks to race conditions.
I have already shared an exercise to help you get more sensitivity about when an implementation...
Read moreWhen saving computed values in the database in your rails app, you must be aware that is possible to find unexpected errors in the result thanks to race conditions.
I have already shared an exercise to help you get more sensitivity about when an implementation...
Read moreWhen saving computed values in the database in your rails app, you must be aware that is possible to find unexpected errors in the result thanks to race conditions.
I have already shared an exercise to help you get more sensitivity about when an implementation...
Read more