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

cleanup dupe profiles #2497

Merged
merged 4 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions app/assets/v2/js/pages/tabs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

function setupTabs(name) {
let sections = document.querySelector(name + '-sections.tab-sections');

if (!sections) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

}
let buttons = document.querySelector(name).lastChild;
let firstButton = null;
let last = null;
Expand Down
89 changes: 89 additions & 0 deletions app/dashboard/management/commands/cleanup_dupe_profiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'''
Copyright (C) 2017 Gitcoin Core

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

'''

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

from dashboard.models import Profile


def combine_profiles(p1, p2):
# p2 is the delete profile, p1 is the save profile
# switch if p2 has the user
# TODO: refactor to use https://github.com/mighty-justice/django-super-deduper

Choose a reason for hiding this comment

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

W291 trailing whitespace

# instead
if p2.user:
p1, p2 = p2, p1

p1.github_access_token = p2.github_access_token if p2.github_access_token else p1.github_access_token
p1.slack_token = p2.slack_token if p2.slack_token else p1.slack_token
p1.slack_repos = p2.slack_repos if p2.slack_repos else p1.slack_repos
p1.slack_channel = p2.slack_channel if p2.slack_channel else p1.slack_channel
p1.email = p2.email if p2.email else p1.email
p1.preferred_payout_address = p2.preferred_payout_address if p2.preferred_payout_address else p1.preferred_payout_address

Choose a reason for hiding this comment

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

E501 line too long (125 > 120 characters)

p1.max_tip_amount_usdt_per_tx = max(p1.max_tip_amount_usdt_per_tx, p2.max_tip_amount_usdt_per_tx)
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.suppress_leaderboard = any([p1.suppress_leaderboard, p2.suppress_leaderboard])
# tips, bounties, fulfillments, and interests , activities, actions
for obj in p2.received_tips.all():
obj.profile = p1
obj.save()
for obj in p2.sent_tips.all():
obj.profile = p1
obj.save()
for obj in p2.bounties_funded.all():
obj.profile = p1
obj.save()
for obj in p2.interested.all():
obj.profile = p1
obj.save()
for obj in p2.fulfilled.all():
obj.profile = p1
obj.save()
for obj in p2.activities.all():
obj.profile = p1
obj.save()
for obj in p2.actions.all():
obj.profile = p1
obj.save()
for obj in p2.token_approvals.all():
obj.profile = p1
obj.save()
for obj in p2.votes.all():
obj.profile = p1
obj.save()
p1.save()
p2.delete()


class Command(BaseCommand):

Choose a reason for hiding this comment

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

E302 expected 2 blank lines, found 1

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check for tips, bounties, fulfillments, and interests on p2 before we delete it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SaptakS @mbeacom what do you think about using this library instead of the custom deduper?


help = 'cleans up users who have duplicate profiles'

def handle(self, *args, **options):

dupes = Profile.objects.values('handle').annotate(Count('handle')).filter(handle__count__gt=1)

for dupe in dupes:
handle = dupe['handle']
profiles = Profile.objects.filter(handle=handle)
print(f"combining {profiles[0].pk} and {profiles[1].pk}")
combine_profiles(profiles[0], profiles[1])
1 change: 1 addition & 0 deletions scripts/crontab
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/us
*/10 * * * * cd gitcoin/coin; bash scripts/run_management_command.bash sync_gas_prices >> /var/log/gitcoin/sync_gas_prices.log 2>&1
1 * * * * cd gitcoin/coin; bash scripts/run_management_command.bash sync_gas_guzzlers >> /var/log/gitcoin/sync_gas_guzzlers.log 2>&1
15 */6 * * * cd gitcoin/coin; bash scripts/run_management_command.bash sync_profiles >> /var/log/gitcoin/sync_profiles.log 2>&1
15 2 * * * cd gitcoin/coin; bash scripts/run_management_command.bash cleanup_dupe_profiles >> /var/log/gitcoin/cleanup_dupe_profiles.log 2>&1
15 4 * * * cd gitcoin/coin; bash scripts/run_management_command.bash cleanup_db_space >> /var/log/gitcoin/cleanup_db_space.log 2>&1
15 5 * * * cd gitcoin/coin; bash scripts/sync_external_bounties.bash >> /var/log/gitcoin/sync_external_bounties.log 2>&1
15 6 * * * cd gitcoin/coin; bash scripts/run_management_command.bash clearsessions >> /var/log/gitcoin/clearsessions.log 2>&1
Expand Down