freedomsponsors/www.freedomsponsors.org — pull request #121 by henriquebastos (2012-12-31 17:59:51+00:00)
Title: Refactor of home view

This PR simplifies the `home` view implementing a new proposal about how to deal with complex queries.

The `home` view is a very simple one, or it should be. Yet, it generates **62 queries** to list *10 sponsoring* issues and *10 kickstarting* issues.

The main problem is how FS relies on it's models.

- FS models are not using the [RelatedManagers](https://docs.djangoproject.com/en/dev/ref/models/relations/) automatically generated by the framework. This ends up generating many queries instead of using joins to retrieve related informations.

- Many of the current existing methods implemented by FS models should be in Custom Managers.

What was done:

1. Reduced from 62 queries to 2.
2. Extracted query complexity to the custom manager IssueManager.
3. Used [url name](https://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns) to avoid hardcoded urls.
4. Cleanedup unreachable code.