Created
April 12, 2012 19:00
-
-
Save mrobers1982/2370116 to your computer and use it in GitHub Desktop.
Remove duplicate user records create by race condition w/lfsp & lfdj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lfsp_remove_dups(domain_id): | |
import datetime | |
import time | |
query = ''' | |
SELECT * | |
FROM user_profiles u1 | |
WHERE domain_id = %s | |
AND EXISTS (SELECT * | |
FROM (SELECT jid | |
FROM user_profiles | |
WHERE domain_id = %s | |
GROUP BY jid | |
HAVING COUNT(*) > 1) u2 | |
WHERE u1.jid = u2.jid) | |
ORDER BY id; | |
''' % (domain_id, domain_id) | |
profiles = list(UserProfile.objects.raw(query)) | |
print "# of Duplicate records: %d" % len(profiles) | |
print datetime.datetime.now() | |
for p in profiles: | |
time.sleep(0.1) | |
if not p.json_config: | |
print "Deleting user with jid: %s" % p.jid | |
# delete django user | |
p.user.delete() | |
# delete lfdj profile | |
p.delete() | |
profiles = list(UserProfile.objects.raw(query)) | |
print "# of Duplicate records: %d" % len(profiles) | |
print datetime.datetime.now() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment