Example #1
0
def migrate_note_full():
    # sqlite to leveldb
    db = xtables.get_note_table()
    content_db = xtables.get_note_content_table()
    for item in db.select():
        note_key = build_note_full_key(item.id)
        ldb_value = dbutil.get(note_key)
        # 如果存在需要比较修改时间
        if ldb_value and item.mtime >= ldb_value.mtime:
            build_full_note(item, content_db)
            dbutil.put(note_key, item)

        if ldb_value is None:
            build_full_note(item, content_db)
            dbutil.put(note_key, item)

    # old key to new key
    for item in dbutil.prefix_iter("note.full:"):
        new_key = build_note_full_key(item.id)
        new_value = dbutil.get(new_key)
        if new_value and item.mtime >= new_value.mtime:
            dbutil.put(new_key, item)

        if new_value is None:
            dbutil.put(new_key, item)

    return "迁移完成!"
Example #2
0
def update_note_content(id, content, data=''):
    if id is None:
        return
    if content is None:
        content = ''
    if data is None:
        data = ''
    db = xtables.get_note_content_table()
    result = db.select_first(where=dict(id=id))
    if result is None:
        db.insert(id=id, content=content, data=data)
    else:
        db.update(where=dict(id=id), content=content, data=data)
Example #3
0
def migrate_note_from_db():
    db = get_note_table()
    content_db = xtables.get_note_content_table()
    for item in db.select():
        note_key = build_note_full_key(item.id)
        ldb_value = dbutil.get(note_key)
        # 如果存在需要比较修改时间
        if ldb_value and item.mtime >= ldb_value.mtime:
            build_full_note(item, content_db)
            dbutil.put(note_key, item)

        if ldb_value is None:
            build_full_note(item, content_db)
            dbutil.put(note_key, item)
Example #4
0
    def GET(self):
        id = xutils.get_argument("id", "")
        name = xutils.get_argument("name", "")
        file = None

        if id == "" and name == "":
            return dict(code="fail", message="id,name至少一个不为空")

        t_file = xtables.get_file_table()
        t_content = xtables.get_note_content_table()
        if id != "":
            file = t_file.select_one(where=dict(id=int(id), is_deleted=0))
        elif name != "":
            file = get_by_name(t_file, name)
        if file is None:
            return dict(code="fail", message="文件不存在")
        id = file.id

        if not xauth.is_admin() and file.creator != xauth.get_current_name():
            return dict(code="fail", message="没有删除权限")

        if file.type == "group":
            children_count = t_file.count(
                where="parent_id=%s AND is_deleted=0" % id)
            if children_count > 0:
                return dict(code="fail", message="分组不为空")

        t_file.update(is_deleted=1,
                      mtime=dateutil.format_time(),
                      where=dict(id=int(id)))
        outdated = t_file.select(
            where="is_deleted=1 AND mtime < $date",
            vars=dict(date=dateutil.before(days=30, format=True)))
        for item in outdated:
            t_file.delete(where=dict(id=item['id']))
            t_content.delete(where=dict(id=item['id']))

        # 删除标签
        t_tag = xtables.get_file_tag_table()
        t_tag.delete(where=dict(file_id=id))
        xmanager.fire("note.remove", dict(id=id))
        return dict(code="success")
Example #5
0
def query_note_conent(id):
    db = xtables.get_note_content_table()
    result = db.select_first(where=dict(id=id))
    if result is None:
        return None, None
    return result.get("content", ""), result.get("data", "")