Recently I’ve been getting into optimizing database structure and queries for performance in Rails. One major thing that’s gone over my head was add indexes.
Thankfully I found an amazing piece of script at Tom Ward’s site. Just run
spring rails c and paste the following code into the console. This will output every place where there should be an index on a foreign key, but isnt.