feat: attention & redis & async

This commit is contained in:
2022-03-20 22:22:08 +08:00
parent e87d8acb7c
commit 58eb7aba6f
16 changed files with 495 additions and 211 deletions

View File

@@ -23,8 +23,9 @@ def mig_post():
r[7] = datetime.fromtimestamp(r[7])
r[8] = datetime.fromtimestamp(r[8])
r[10] = r[10] or False # comment
r.insert(4, r[2].startswith('[tmp]\n'))
c_new.execute(
'INSERT OR REPLACE INTO posts VALUES({})'.format(','.join(['?'] * 13)),
'INSERT OR REPLACE INTO posts VALUES({})'.format(','.join(['?'] * 14)),
r
)
db_new.commit()
@@ -42,27 +43,39 @@ def mig_user():
def mig_comment():
rs = c_old.execute(
'SELECT id, name_hash, author_title, content, timestamp, deleted, post_id '
'FROM comment'
)
for r in rs:
r = list(r)
r[2] = r[2] or ''
r[4] = datetime.fromtimestamp(r[4])
r[5] = r[5] or False
c_new.execute(
'INSERT OR REPLACE INTO comments VALUES({})'.format(','.join(['?'] * 7)),
r
_start = 0
_step = 1000
while True:
print("comment loop...", _start)
rs = c_old.execute(
'SELECT id, name_hash, author_title, content, timestamp, deleted, post_id '
'FROM comment WHERE id > ? ORDER BY id LIMIT ?',
(_start, _step)
)
db_new.commit()
r = None
for r in rs:
r = list(r)
r[2] = r[2] or ''
r[4] = datetime.fromtimestamp(r[4])
r[5] = r[5] or False
r.insert(2, r[3].startswith('[tmp]\n'))
c_new.execute(
'INSERT OR REPLACE INTO comments VALUES({})'.format(','.join(['?'] * 8)),
r
)
if not r:
break
db_new.commit()
_start = r[0]
if __name__ == '__main__':
# mig_post()
# mig_user()
mig_post()
mig_user()
mig_comment()
pass
c_old.close()
c_new.close()