Performence optimization for projects and documents pages

https://www.pivotaltracker.com/s/projects/982890/stories/80166130

Fix N+1 query problems in documents and projects controllers.