2023-06-08 - DB Advanced


main topics


Situation:

# books controller
@books = Book.all

# books view
@books.each do |book|
  book.author.name # one query for each author
end
Important

Very easy to spot if you see a bunch of repeated queries in the logs

Solution:

@books = Book.includes(:author).all

Useful gem: https://github.com/flyerhzm/bullet
Le Wagon's tutorial: https://kitt.lewagon.com/knowledge/tutorials/n_plus_one


Free dataset: https://www.kaggle.com/datasets/olistbr/brazilian-ecommerce


Rails Admin

bundle add rails_admin
rails generate rails_admin:install
# answer the question

great guy to follow: https://github.com/ankane

author of the blazer gem
https://github.com/ankane/blazer

really cool for business analytics