Exemple #1
0
def clear_explore_cache(gist, user, organization):
    keys = [
        'gists:explore:user:{oid}:{uid}'.format(uid=user.id, oid=organization.id), \
    ]
    if not gist.private:
        keys.append('gists:explore:{oid}'.format(oid=organization.id))
    backend.delete_many(*keys)
Exemple #2
0
def clear_watcher_cache(user, gist, organization):
    keys = [
        'gists:watchers:{gid}'.format(gid=gist.id), \
        'gists:watcher:{uid}:{gid}'.format(uid=user.id, gid=gist.id), \
        'user:watch:gists:{uid}:{oid}'.format(uid=user.id, oid=organization.id), \
    ]
    backend.delete_many(*keys)
Exemple #3
0
def clear_key_cache(key, user=None):
    keys = [
        'account:key:{kid}'.format(kid=key.id), \
        'account:key:{finger}'.format(finger=key.finger), \
    ]
    if user:
        keys.append('account:keys:{uid}'.format(uid=user.id))
    backend.delete_many(*keys)
Exemple #4
0
def clear_alias_cache(user, email, aid=None):
    keys = [
        'account:alias:{email}'.format(email=email),
        'account:alias:user:{uid}'.format(uid=user.id),
    ]
    if aid:
        keys.append('account:alias:{aid}'.format(aid=aid))
    backend.delete_many(*keys)
Exemple #5
0
def clear_watcher_cache(user, repo, organization, team=None):
    keys = [
        'repos:watchers:{rid}'.format(rid=repo.id), \
        'repos:watcher:{uid}:{rid}'.format(uid=user.id, rid=repo.id), \
        'user:watches:organization:{uid}:{oid}'.format(uid=user.id, oid=organization.id), \
    ]
    if team:
        keys.append('user:watches:team:{uid}:{oid}:{tid}'.format(
            uid=user.id, oid=organization.id, tid=team.id))
    backend.delete_many(*keys)
Exemple #6
0
def clear_organization_cache(organization, user=None, old_git=''):
    keys = [
        'organization:{oid}'.format(oid=organization.id),
        'organization:git:{git}'.format(git=old_git or organization.git),
    ]
    if user:
        keys.append('organization:member:{oid}:{uid}'.format(
            oid=organization.id, uid=user.id))
        keys.append('organization:member:{uid}'.format(uid=user.id))
    backend.delete_many(*keys)
Exemple #7
0
def clear_explore_cache(organization, uid, team=None):
    keys = [
        'repos:explore:{oid}'.format(oid=organization.id), \
        'repos:explore:user:{oid}:{uid}'.format(oid=organization.id, uid=uid), \
    ]
    if team:
        keys.append('repos:explore:team:{oid}:{tid}'.format(
            oid=organization.id, tid=team.id))
        keys.append('repos:explore:team:user:{oid}:{tid}:{uid}'.format(
            oid=organization.id, tid=team.id, uid=uid))
    backend.delete_many(*keys)
Exemple #8
0
def clear_repo_cache(repo, organization, team=None, old_path=None, need=True):
    keys = [
        'repos:{rid}'.format(rid=repo.id), \
        'repos:forks:{rid}'.format(rid=repo.id), \
        'repos:{oid}:{path}'.format(oid=organization.id, path=old_path or repo.path),
    ]
    if need:
        clear_organization_cache(organization)
        if team:
            clear_team_cache(organization, team)
    backend.delete_many(*keys)
Exemple #9
0
def clear_gist_cache(gist, organization=None):
    keys = [
        'gists:{gid}'.format(gid=gist.id), \
        'gists:forks:{gid}'.format(gid=gist.id), \
        'gists:path:{path}'.format(path=gist.path), \
    ]
    if gist.private:
        keys.append('gists:hidden:{private}'.format(private=gist.private))
    if organization:
        clear_organization_cache(organization)
    backend.delete_many(*keys)
Exemple #10
0
def clear_team_cache(organization, team, user=None):
    keys = [
        'organization:team:team:{tid}'.format(tid=team.id), \
        'organization:team:members:{tid}'.format(tid=team.id), \
        'organization:team:{oid}'.format(oid=organization.id), \
        'organization:team:{oid}:{name}'.format(oid=organization.id, name=team.name),
    ]

    if user:
        keys.append('organization:team:member:{tid}:{uid}'.format(tid=team.id,
                                                                  uid=user.id))
    backend.delete_many(*keys)
Exemple #11
0
def delete_gist(user, gist, organization):
    try:
        keys = []
        db.session.delete(gist)
        organization.gists = Organization.gists - 1
        db.session.add(organization)
        user_gist = get_user_gist(organization.id, user.id)
        user_gist.count = UserGists.count - 1
        db.session.add(user_gist)
        watchers = get_gist_watchers(gist.id)
        keys.append('gists:watchers:{gid}'.format(gid=gist.id))
        for watcher in watchers:
            db.session.delete(watcher)
            keys.append('gists:watcher:{uid}:{gid}'.format(uid=watcher.uid,
                                                           gid=gist.id))
            keys.append('user:watch:gists:{uid}:{oid}'.format(
                uid=watcher.uid, oid=organization.id))
        jagare = get_jagare(gist.id, gist.parent)
        ret, error = jagare.delete(gist.get_real_path())
        if not ret:
            db.session.rollback()
            return error
        if gist.parent > 0:
            parent_gist = get_gist(gist.parent)
            parent_gist.forks = Gists.forks - 1
            db.session.add(parent_gist)
        db.session.commit()
        clear_gist_cache(gist, organization)
        if gist.parent > 0:
            clear_gist_cache(parent_gist)
        clear_explore_cache(gist, user, organization)
        from actions.gists import after_delete_gist
        after_delete_gist(gist, asynchronous=True)
        backend.delete_many(*keys)
        return None
    except Exception, e:
        db.session.rollback()
        logger.exception(e)
        return code.UNHANDLE_EXCEPTION
Exemple #12
0
def delete_repo(organization, repo, team=None):
    try:
        keys = []
        db.session.delete(repo)
        organization.repos = Organization.repos - 1
        db.session.add(organization)
        if team:
            team.repos = Team.repos - 1
            db.session.add(team)
        commiters = get_repo_commiters(repo.id)
        for commiter in commiters:
            db.session.delete(commiter)
            keys.append('repos:commiters:{rid}'.format(rid=repo.id))
            keys.append('repos:commiter:{uid}:{rid}'.format(uid=commiter.uid,
                                                            rid=repo.id))
        watchers = get_repo_watchers(repo.id)
        keys.append('repos:watchers:{rid}'.format(rid=repo.id))
        for watcher in watchers:
            db.session.delete(watcher)
            keys.append('repos:watcher:{uid}:{rid}'.format(uid=watcher.uid,
                                                           rid=repo.id))
            keys.append('user:watches:organization:{uid}:{oid}'.format(
                uid=watcher.uid, oid=organization.id))
            if team:
                keys.append('user:watches:team:{uid}:{oid}:{tid}'.format(
                    uid=watcher.uid, oid=organization.id, tid=team.id))
        db.session.commit()
        clear_repo_cache(repo, organization, team)
        clear_explore_cache(organization, repo.uid, team)
        from actions.repos import after_delete_repo
        after_delete_repo(repo, asynchronous=True)
        backend.delete_many(*keys)
        return None
    except Exception, e:
        db.session.rollback()
        logger.exception(e)
        return code.UNHANDLE_EXCEPTION
Exemple #13
0
def clear_commiter_cache(user, repo):
    keys = [
        'repos:commiters:{rid}'.format(rid=repo.id), \
        'repos:commiter:{uid}:{rid}'.format(uid=user.id, rid=repo.id)
    ]
    backend.delete_many(*keys)
Exemple #14
0
def clear_user_cache(user):
    keys = [
        'account:%s' % key for key in [str(user.id), user.name, user.email]
    ]
    backend.delete_many(*keys)
Exemple #15
0
def clear_user_gist_cache(user, organization):
    keys = [
        'gists:user:{oid}:{uid}'.format(oid=organization.id, uid=user.id), \
    ]
    backend.delete_many(*keys)