Speed up get_perms

Split a single large permissions query into multiple queries to improve
performance
Merge pull request #134 from sustainingtechnologies/performance

Speed up get_perms