simplify and index review queries (bug 667951)

This commit is contained in:
Jeff Balogh 2011-06-29 16:46:20 -07:00
Родитель ae59dbf1a9
Коммит 458cc25502
2 изменённых файлов: 5 добавлений и 6 удалений

Просмотреть файл

@ -17,13 +17,10 @@ from versions.models import Version
class ReviewManager(amo.models.ManagerBase):
def get_query_set(self):
qs = super(ReviewManager, self).get_query_set()
return qs.select_related('user', 'version')
def valid(self):
"""Get all reviews with rating > 0 that aren't replies."""
return self.filter(reply_to=None, rating__gt=0)
"""Get all reviews that aren't replies."""
# Use extra because Django wants to do a LEFT OUTER JOIN.
return self.extra(where=['reply_to IS NULL'])
def latest(self):
"""Get all the latest valid reviews."""

Просмотреть файл

@ -0,0 +1,2 @@
CREATE INDEX latest_reviews
ON reviews (reply_to, is_latest, addon_id, created);