A round of changes to speed up /list/popular
parent
2a0c572211
commit
a1e944b795
|
@ -25,13 +25,11 @@ def supporting_users(work, how_many):
|
|||
return user_list
|
||||
|
||||
def work_list_users(work_list, how_many):
|
||||
users = User.objects.filter(wishlist__works__in=work_list).distinct().reverse()
|
||||
count = users.count()
|
||||
if count <= how_many :
|
||||
user_list = users[0: count]
|
||||
else :
|
||||
user_list = users[0: how_many]
|
||||
return user_list
|
||||
"""return up to how_many users with one of the works on work_list in their wishlist"""
|
||||
#users = User.objects.filter(wishlist__works__in=work_list).distinct().reverse()
|
||||
# for MySQL, avoiding a nested query is more efficient: https://docs.djangoproject.com/en/dev/ref/models/querysets/#in
|
||||
users = User.objects.filter(wishlist__works__in=list(work_list)).distinct().reverse()
|
||||
return users.all()[0:how_many]
|
||||
|
||||
def campaign_list_users(campaign_list, how_many):
|
||||
users = User.objects.filter(wishlist__works__campaigns__in=campaign_list).distinct().reverse()
|
||||
|
|
|
@ -188,7 +188,8 @@ class WorkListView(ListView):
|
|||
|
||||
def work_set_counts(self,work_set):
|
||||
counts={}
|
||||
counts['unglued'] = work_set.annotate(ebook_count=Count('editions__ebooks')).filter(ebook_count__gt=0).count()
|
||||
# counts['unglued'] = work_set.annotate(ebook_count=Count('editions__ebooks')).filter(ebook_count__gt=0).count()
|
||||
counts['unglued'] = work_set.filter(editions__ebooks__isnull=False).distinct().count()
|
||||
counts['unglueing'] = work_set.filter(campaigns__status='ACTIVE').count()
|
||||
counts['wished'] = work_set.count() - counts['unglued'] - counts['unglueing']
|
||||
return counts
|
||||
|
|
Loading…
Reference in New Issue