Commit 700f92de authored by Pietro Albini's avatar Pietro Albini

Speed up skipping existing data

parent 61c317ea
...@@ -62,17 +62,19 @@ class Migrator: ...@@ -62,17 +62,19 @@ class Migrator:
"location", "last_seen", "location", "last_seen",
] ]
# Load existing users
existing = [u[0] for u in self.askbot_query(
"SELECT id FROM auth_user;"
)]
last_id = 0 last_id = 0
tbl = "auth_user a, forum_user f WHERE a.id = f.user_ptr_id" tbl = "auth_user a, forum_user f WHERE a.id = f.user_ptr_id"
for user in self.osqa.table_items(tbl, what="users"): for user in self.osqa.table_items(tbl, what="users"):
last_id = user["id"] last_id = user["id"]
# Check if the user already exists # Check if the user already exists
try: if user["id"] in existing:
self.models.User.objects.get(id=user["id"])
continue continue
except self.models.User.DoesNotExist:
pass
# Create a new User object # Create a new User object
new = self.models.User() new = self.models.User()
...@@ -104,17 +106,19 @@ class Migrator: ...@@ -104,17 +106,19 @@ class Migrator:
def migrate_user_logins(self): def migrate_user_logins(self):
"""Migrate the login table""" """Migrate the login table"""
# Load existing users
existing = [u[0] for u in self.askbot_query(
"SELECT id FROM django_authopenid_userassociation;"
)]
last_id = 0 last_id = 0
table = "forum_authkeyuserassociation" table = "forum_authkeyuserassociation"
for login in self.osqa.table_items(table, what="user logins"): for login in self.osqa.table_items(table, what="user logins"):
last_id = login["id"] last_id = login["id"]
# Check if the association already exists # Check if the login entry already exists
try: if login["id"] in existing:
self.openid_models.UserAssociation.objects.get(id=login["id"])
continue continue
except self.openid_models.UserAssociation.DoesNotExist:
pass
# Migrate login data # Migrate login data
assoc = self.openid_models.UserAssociation() assoc = self.openid_models.UserAssociation()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment