Exemple #1
0
def update_children_count(parent_id, db=None):
    if parent_id is None or parent_id == "":
        return
    if db is None:
        db = get_file_db()
    group_count = db.count(where="parent_id=$parent_id AND is_deleted=0",
                           vars=dict(parent_id=parent_id))
    db.update(size=group_count, where=dict(id=parent_id))
Exemple #2
0
def count_user_note(creator):
    if xconfig.DB_ENGINE == "sqlite":
        db    = xtables.get_file_table()
        where = "is_deleted = 0 AND creator = $creator AND type != 'group'"
        count = db.count(where, vars = dict(creator = xauth.get_current_name()))
    else:
        def count_func(key, value):
            if value.is_deleted:
                return False
            return value.creator == creator and type != 'group'
        count = dbutil.prefix_count("note_tiny:%s" % creator, count_func)
    return count
Exemple #3
0
def count_user_note(creator):
    t = Timer()
    t.start()
    count_key = "[%s]note.count" % creator
    count = cacheutil.get(count_key)
    if count is None:
        db = xtables.get_file_table()
        where = "is_deleted = 0 AND creator = $creator AND type != 'group'"
        count = db.count(where, vars=dict(creator=xauth.get_current_name()))
        cacheutil.set(count_key, count, expire=600)
    t.stop()
    xutils.trace("NoteDao.CountRecentEdit", "", t.cost_millis())
    return count
Exemple #4
0
def count_note(creator, parent_id):
    if xconfig.DB_ENGINE == "sqlite":
        db = xtables.get_note_table()
        where_sql = "parent_id=$parent_id AND is_deleted=0 AND (creator=$creator OR is_public=1)"
        amount    = db.count(where = where_sql,
                    vars=dict(parent_id=parent_id, creator=creator))
        return amount
    else:
        # TODO 添加索引优化
        def list_note_func(key, value):
            if value.is_deleted:
                return False
            if value.type == "group":
                return False
            return (value.is_public or value.creator == creator) and str(value.parent_id) == str(parent_id)

        return dbutil.prefix_count("note_tiny", list_note_func)