def record_history(ctx): id = ctx.get("id") content = ctx.get("content") version = ctx.get("version") mtime = ctx.get("mtime") name = ctx.get("name") table = xtables.get_note_history_table() table.insert(name=name, note_id=id, content=content, version=version, mtime=mtime)
def GET(self): table = xtables.get_note_history_table() note_id = xutils.get_argument("id") creator = xauth.current_name() note = xutils.call("note.get_by_id_creator", note_id, creator) if note is None: history_list = [] else: history_list = table.select(where=dict(note_id=note_id), order="mtime DESC") return xtemplate.render("note/history_list.html", history_list=history_list, show_aside=True)
def GET(self): note_id = xutils.get_argument("id") version = xutils.get_argument("version") table = xtables.get_note_history_table() creator = xauth.current_name() note = xutils.call("note.get_by_id_creator", note_id, creator) content = "" if note != None: note = table.select_first( where=dict(note_id=note_id, version=version)) if note != None: content = note.content return dict(code="success", data=content)
def migrate_note_history(): # sqlite to kv db = xtables.get_note_history_table() for item in db.select(): dbutil.put("note_history:%s:%s" % (item.note_id, item.version), item) # old_key to new_key for item in dbutil.prefix_iter("note.history"): # 这里leveldb第一版没有note_id,而是id字段 old_key = "note.history:%s:%s" % (item.id, item.version) new_key = "note_history:%s:%s" % (item.id, item.version) new_value = dbutil.get(new_key) if new_value and (new_value.mtime is None or item.mtime > new_value.mtime): dbutil.put(new_key, item) dbutil.delete(old_key) if new_value is None: dbutil.put(new_key, item) dbutil.delete(old_key) return "迁移完成!"