Try not to loop through associations inside jobs - Andy Croll
13-Feb-2023 839
One of the downsides of using Ruby to interact with your database, rather than SQL directly, is that it’s easy to accidentally give yourself performance headaches via running multiple very similar queries. Although the advantages of using Active Record (or something similar) are generally worth it!This is typically referred to as an N 1 problem. They occur most often seen when you display an Active Record object in a view and show all of the associated records that belong_to to it. When lots of records do need to be loaded or saved to the database you can putting this heavier database work in asynchronous jobs.
Try not to loop through associations inside jobs - Andy Croll #ruby #rubydeveloper #rubyonrails #through #associations #inside #Croll https://rubyonrails.ba/link/try-not-to-loop-through-associations-inside-jobs-andy-croll