crowbar/barclamp-crowbar — pull request #1057 by bkutil (2014-06-11 08:48:38+00:00)
Title: Eager load roles and proposals for NodesHelper

In certain cases, it makes sense to eager load all roles/proposals to avoid 'N+1' queries. I.e. fetch all related records and filter them, instead of individually fetching e.g. a role + N proposals that belong to it.

On my setup, a loading a single chef object takes ~ 20ms, while fetching all roles/proposals takes ~ 100ms (There are 62 / 32 of them in the db.)

So it seems that anything above 5 records should be faster with an eager load. That of course assumes that loading everything at once won't slow down too much with more records in the DB.

Use filtering from pre-fetched records and cache the collection of all records from the db.

This reduces the admin node show view load time from 900 ms to roughly a half.

Feel free to independently verify/refute this!