SQL performance improved. Closes #403

The benefit with this commit is really interesting: from 22 queries it has been reduce to only 2, making it really fast.
Merge pull request #405 from PyBossa/issue-403-profile-slow

SQL performance improved. Closes #403