Preload environments to resolve N+1
Why
While trying to address a deletion statement timeout issue, an N+1 arising from our usage of fast_destroy_all
was discovered that results in a SELECT on each environment:
Environment Load (0.2ms) SELECT "environments".* FROM "environments" WHERE "environments"."id" = 1880 LIMIT 1 /*application:console,db_config_name:main,console_hostname:,console_username:,line:/app/models/deployment.rb:433:in `ref_path'*/
Environment Load (0.1ms) SELECT "environments".* FROM "environments" WHERE "environments"."id" = 1881 LIMIT 1
See this comment for more.
What
- update the method to preload environments to resolve the N+1