Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dupe profile cleanup part 2 #2696

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def setup_lang(request, user):


def sync_profile(handle, user=None, hide_profile=True):
handle = handle.strip().replace('@', '')
data = get_user(handle)
email = ''
is_error = 'name' not in data.keys()
Expand Down
21 changes: 17 additions & 4 deletions app/dashboard/management/commands/cleanup_dupe_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from django.core.management.base import BaseCommand
from django.db.models import Count
from django.db.models.functions import Lower

from dashboard.models import Profile

Expand All @@ -40,7 +41,7 @@ def combine_profiles(p1, p2):
p1.max_tip_amount_usdt_per_week = max(p1.max_tip_amount_usdt_per_week, p2.max_tip_amount_usdt_per_week)
p1.max_num_issues_start_work = max(p1.max_num_issues_start_work, p2.max_num_issues_start_work)
p1.trust_profile = any([p1.trust_profile, p2.trust_profile])
p1.hide_profile = any([p1.hide_profile, p2.hide_profile])
#p1.hide_profile = any([p1.hide_profile, p2.hide_profile]) not valid, all p2s have hide profile because its default
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved
p1.suppress_leaderboard = any([p1.suppress_leaderboard, p2.suppress_leaderboard])
p1.user = p2.user if p2.user else p1.user
# tips, bounties, fulfillments, and interests , activities, actions
Expand Down Expand Up @@ -80,11 +81,23 @@ class Command(BaseCommand):
help = 'cleans up users who have duplicate profiles'

def handle(self, *args, **options):
whitespace_profiles = Profile.objects.filter(handle__endswith=' ')
print(f" - {whitespace_profiles.count()} whitespace profiles")
for profile in whitespace_profiles:
profile.handle = profile.handle.strip()
profile.save()

dupes = Profile.objects.values('handle').annotate(Count('handle')).filter(handle__count__gt=1)
at_profiles = Profile.objects.filter(handle__startswith='@')
print(f" - {at_profiles.count()} at_profiles")
for profile in at_profiles:
profile.handle = profile.handle.replace('@', '')
profile.save()

dupes = Profile.objects.exclude(handle=None).annotate(handle_lower=Lower("handle")).values('handle_lower').annotate(handle_lower_count=Count('handle_lower')).filter(handle_lower_count__gt=1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E501 line too long (198 > 120 characters)

print(f" - {dupes.count()} dupes")

for dupe in dupes:
handle = dupe['handle']
profiles = Profile.objects.filter(handle=handle).distinct("pk")
handle = dupe['handle_lower']
profiles = Profile.objects.filter(handle__iexact=handle).distinct("pk")
print(f"combining {handle}: {profiles[0].pk} and {profiles[1].pk}")
combine_profiles(profiles[0], profiles[1])
6 changes: 3 additions & 3 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ def get_users(request):
profile_json['preferred_payout_address'] = user.preferred_payout_address
results.append(profile_json)
# try github
if not profiles:
if not len(results):
search_results = search_users(q, token=token)
for result in search_results:
profile_json = {}
Expand All @@ -1678,10 +1678,10 @@ def get_users(request):
profile_json['avatar_url'] = result.avatar_url
profile_json['preferred_payout_address'] = None
# dont dupe github profiles and gitcoin profiles in user search
if profile_json['text'].lower() not in [p['text'].lower() for p in profiles]:
if profile_json['text'].lower() not in [p['text'].lower() for p in profiles]:
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved
results.append(profile_json)
# just take users word for it
if not profiles:
if not len(results):
profile_json = {}
profile_json['id'] = -1
profile_json['text'] = q
Expand Down