Optimize SQL queries for puppetclass edit page