Commit 36cb8fc9 authored by Pietro Albini's avatar Pietro Albini

Fix some users not properly migrated to Askbot

parent 700f92de
...@@ -69,7 +69,7 @@ class Migrator: ...@@ -69,7 +69,7 @@ class Migrator:
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", order="id"):
last_id = user["id"] last_id = user["id"]
# Check if the user already exists # Check if the user already exists
...@@ -112,8 +112,8 @@ class Migrator: ...@@ -112,8 +112,8 @@ class Migrator:
)] )]
last_id = 0 last_id = 0
table = "forum_authkeyuserassociation" t = "forum_authkeyuserassociation"
for login in self.osqa.table_items(table, what="user logins"): for login in self.osqa.table_items(t, what="user logins", order="id"):
last_id = login["id"] last_id = login["id"]
# Check if the login entry already exists # Check if the login entry already exists
......
...@@ -73,12 +73,17 @@ class Connection: ...@@ -73,12 +73,17 @@ class Connection:
cursor.execute(query, params) cursor.execute(query, params)
return cursor.fetchall() return cursor.fetchall()
def table_items(self, name, batch=100, what=None): def table_items(self, name, batch=100, what=None, order=None):
"""Return items in a table without loading all of them in memory""" """Return items in a table without loading all of them in memory"""
# This loads elements in batches, to avoid loading too much stuff in # This loads elements in batches, to avoid loading too much stuff in
# memory and going OOM # memory and going OOM
total = self.query("SELECT COUNT(*) FROM %s;" % name)[0][0] total = self.query("SELECT COUNT(*) FROM %s;" % name)[0][0]
if order is not None:
order = "ORDER BY %s" % order
else:
order = ""
pb = None pb = None
if what is not None: if what is not None:
pb = ProgressBar("Migrating %s" % what, what, total) pb = ProgressBar("Migrating %s" % what, what, total)
...@@ -90,8 +95,8 @@ class Connection: ...@@ -90,8 +95,8 @@ class Connection:
for i in range(steps): for i in range(steps):
query = ( query = (
"SELECT * FROM %s LIMIT %s OFFSET %s;" % "SELECT * FROM %s %s LIMIT %s OFFSET %s;" %
(name, batch, i * batch) (name, order, batch, i * batch)
) )
for (i2, item) in enumerate(self.query(query)): for (i2, item) in enumerate(self.query(query)):
if pb is not None: if pb is not None:
......
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