Skip to content

Commit

Permalink
Fix user search (#313)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9a1d3c3)
  • Loading branch information
hieplpvip authored and magnified103 committed Jul 7, 2023
1 parent 1159e8f commit 8121a8b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions judge/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ class UserList(QueryStringSortMixin, InfinitePaginationMixin, DiggPaginatorMixin
default_sort = '-performance_points'

def get_queryset(self):
return (Profile.objects.filter(is_unlisted=False).order_by(self.order)
return (Profile.objects.filter(is_unlisted=False).order_by(self.order, 'id')
.prefetch_related(Prefetch('user', queryset=User.objects.only('username', 'first_name')))
.prefetch_related(Prefetch('organizations',
queryset=Organization.objects.filter(is_unlisted=False).only('name', 'id', 'slug')))
Expand Down Expand Up @@ -590,7 +590,7 @@ class ContribList(QueryStringSortMixin, DiggPaginatorMixin, TitleMixin, ListView
default_sort = '-contribution_points'

def get_queryset(self):
return (Profile.objects.filter(is_unlisted=False).order_by(self.order)
return (Profile.objects.filter(is_unlisted=False).order_by(self.order, 'id')
.prefetch_related(Prefetch('user', queryset=User.objects.only('username', 'first_name')))
.prefetch_related(Prefetch('organizations',
queryset=Organization.objects.filter(is_unlisted=False).only('name', 'id', 'slug')))
Expand Down Expand Up @@ -631,9 +631,13 @@ def user_ranking_redirect(request):
except KeyError:
raise Http404()
user = get_object_or_404(Profile, user__username=username)
rank = Profile.objects.filter(is_unlisted=False, performance_points__gt=user.performance_points).count()
# Assume using MySQL. NULL is considered smaller than any non-NULL value.
if user.rating is None:
rank = Profile.objects.filter(is_unlisted=False, rating__isnull=False).count()
else:
rank = Profile.objects.filter(is_unlisted=False, rating__gt=user.rating).count()
rank += Profile.objects.filter(
is_unlisted=False, performance_points__exact=user.performance_points, id__lt=user.id,
is_unlisted=False, rating__exact=user.rating, id__lt=user.id,
).count()
page = rank // UserList.paginate_by
return HttpResponseRedirect('%s%s#!%s' % (reverse('user_list'), '?page=%d' % (page + 1) if page else '', username))
Expand Down

0 comments on commit 8121a8b

Please sign in to comment.