diff --git a/core/userlists.py b/core/userlists.py index fe81545c..dfb89cd0 100644 --- a/core/userlists.py +++ b/core/userlists.py @@ -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() diff --git a/frontend/views.py b/frontend/views.py index e5bc4fcb..72bfa391 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -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