https://bugzilla.redhat.com/show_bug.cgi?id=1097861#c37 There should be no reason it needs to do that expensive SELECT. It adds about 4 seconds to each call in our prod environment which adds up to a lot.
Oops, this was the system releasing code path in update_dirty_job(), not provision_scheduled_recipe().
https://gerrit.beaker-project.org/6091 Also fixed this while I was in there (although it's unrelated): https://gerrit.beaker-project.org/6092
Okay so there *is* the same problem in provision_scheduled_recipe() also, and that's because it is ultimately the same code system.enqueue_command() which was needlessly SELECT'ing out the commands before inserting. So the patch above fixes the same problem in both places.