예제 #1
0
    def get(self, request, group):
        limit = request.GET.get('limit', None)
        if limit is not None:
            limit = int(limit) + 1  # the target group will always be included

        results = filter(
            lambda group_id__scores: group_id__scores[0] != group.id,
            features.compare(group, limit=limit)
        )

        serialized_groups = apply_values(
            functools.partial(serialize, user=request.user),
            Group.objects.in_bulk([group_id for group_id, scores in results])
        )

        # TODO(tkaemming): This should log when we filter out a group that is
        # unable to be retrieved from the database. (This will soon be
        # unexpected behavior, but still possible.)
        return Response(
            filter(
                lambda group_id__scores: group_id__scores[0] is not None,
                map(
                    lambda group_id__scores: (serialized_groups.get(group_id__scores[0]), group_id__scores[1], ),
                    results,
                ),
            ),
        )
예제 #2
0
    def get(self, request, group):
        limit = request.GET.get('limit', None)
        if limit is not None:
            limit = int(limit) + 1  # the target group will always be included

        results = filter(
            lambda group_id__scores: group_id__scores[0] != group.id,
            features.compare(group, limit=limit))

        serialized_groups = apply_values(
            functools.partial(serialize, user=request.user),
            Group.objects.in_bulk([group_id for group_id, scores in results]))

        # TODO(tkaemming): This should log when we filter out a group that is
        # unable to be retrieved from the database. (This will soon be
        # unexpected behavior, but still possible.)
        return Response(
            filter(
                lambda group_id__scores: group_id__scores[0] is not None,
                map(
                    lambda group_id__scores: (
                        serialized_groups.get(group_id__scores[0]),
                        group_id__scores[1],
                    ),
                    results,
                ),
            ), )
예제 #3
0
    def get(self, request, group):
        # TODO(tkaemming): This should have a limit somewhere.
        results = filter(
            lambda (group_id, scores): group_id != group.id,
            features.query(group)
        )

        serialized_groups = apply_values(
            functools.partial(serialize, user=request.user),
            Group.objects.in_bulk([group_id for group_id, scores in results])
        )

        # TODO(tkaemming): This should log when we filter out a group that is
        # unable to be retrieved from the database. (This will soon be
        # unexpected behavior, but still possible.)
        return Response(
            filter(
                lambda (group_id, scores): group_id is not None,
                map(
                    lambda (group_id, scores): (
                        serialized_groups.get(group_id),
                        scores,
                    ),
                    results,
                ),
            ),
        )
예제 #4
0
    def get_attrs(self, item_list, user):
        # TODO(dcramer); assert on relations
        users = {d["id"]: d for d in serialize({i.user for i in item_list if i.user_id}, user)}

        commit_ids = {
            i.data["commit"] for i in item_list if i.type == Activity.SET_RESOLVED_IN_COMMIT
        }
        if commit_ids:
            commit_list = list(Commit.objects.filter(id__in=commit_ids))
            commits_by_id = {c.id: d for c, d in zip(commit_list, serialize(commit_list, user))}
            commits = {
                i: commits_by_id.get(i.data["commit"])
                for i in item_list
                if i.type == Activity.SET_RESOLVED_IN_COMMIT
            }
        else:
            commits = {}

        pull_request_ids = {
            i.data["pull_request"]
            for i in item_list
            if i.type == Activity.SET_RESOLVED_IN_PULL_REQUEST
        }
        if pull_request_ids:
            pull_request_list = list(PullRequest.objects.filter(id__in=pull_request_ids))
            pull_requests_by_id = {
                c.id: d for c, d in zip(pull_request_list, serialize(pull_request_list, user))
            }
            pull_requests = {
                i: pull_requests_by_id.get(i.data["pull_request"])
                for i in item_list
                if i.type == Activity.SET_RESOLVED_IN_PULL_REQUEST
            }
        else:
            pull_requests = {}

        groups = apply_values(
            functools.partial(serialize, user=user),
            Group.objects.in_bulk(
                {i.data["source_id"] for i in item_list if i.type == Activity.UNMERGE_DESTINATION}
                | {i.data["destination_id"] for i in item_list if i.type == Activity.UNMERGE_SOURCE}
            ),
        )

        return {
            item: {
                "user": users[str(item.user_id)] if item.user_id else None,
                "source": groups.get(item.data["source_id"])
                if item.type == Activity.UNMERGE_DESTINATION
                else None,
                "destination": groups.get(item.data["destination_id"])
                if item.type == Activity.UNMERGE_SOURCE
                else None,
                "commit": commits.get(item),
                "pull_request": pull_requests.get(item),
            }
            for item in item_list
        }
예제 #5
0
파일: activity.py 프로젝트: Kayle009/sentry
    def get_attrs(self, item_list, user):
        # TODO(dcramer); assert on relations
        users = {d['id']: d for d in serialize(set(i.user for i in item_list if i.user_id), user)}

        commit_ids = {
            i.data['commit'] for i in item_list if i.type == Activity.SET_RESOLVED_IN_COMMIT
        }
        if commit_ids:
            commit_list = list(Commit.objects.filter(id__in=commit_ids))
            commits_by_id = {c.id: d for c, d in zip(commit_list, serialize(commit_list, user))}
            commits = {
                i: commits_by_id.get(i.data['commit']) for i in item_list
                if i.type == Activity.SET_RESOLVED_IN_COMMIT
            }
        else:
            commits = {}

        pull_request_ids = {
            i.data['pull_request'] for i in item_list if i.type == Activity.SET_RESOLVED_IN_PULL_REQUEST
        }
        if pull_request_ids:
            pull_request_list = list(PullRequest.objects.filter(id__in=pull_request_ids))
            pull_requests_by_id = {
                c.id: d for c, d in zip(
                    pull_request_list, serialize(
                        pull_request_list, user))}
            pull_requests = {
                i: pull_requests_by_id.get(i.data['pull_request']) for i in item_list
                if i.type == Activity.SET_RESOLVED_IN_PULL_REQUEST
            }
        else:
            pull_requests = {}

        groups = apply_values(
            functools.partial(serialize, user=user),
            Group.objects.in_bulk(
                set(
                    i.data['source_id'] for i in item_list if i.type == Activity.UNMERGE_DESTINATION
                ) | set(
                    i.data['destination_id'] for i in item_list if i.type == Activity.UNMERGE_SOURCE
                )
            )
        )

        return {
            item: {
                'user':
                users[six.text_type(item.user_id)] if item.user_id else None,
                'source':
                groups.get(item.data['source_id'])
                if item.type == Activity.UNMERGE_DESTINATION else None,
                'destination':
                groups.get(item.data['destination_id'])
                if item.type == Activity.UNMERGE_SOURCE else None,
                'commit': commits.get(item),
                'pull_request': pull_requests.get(item),
            } for item in item_list
        }
예제 #6
0
    def get_attrs(self, item_list, user):
        # TODO(dcramer); assert on relations
        users = {
            d['id']: d
            for d in serialize(set(
                i.user for i in item_list if i.user_id), user)
        }

        commit_ids = {
            i.data['commit']
            for i in item_list if i.type == Activity.SET_RESOLVED_IN_COMMIT
        }
        if commit_ids:
            commit_list = list(Commit.objects.filter(id__in=commit_ids))
            commits_by_id = {
                c.id: d
                for c, d in zip(commit_list, serialize(commit_list, user))
            }
            commits = {
                i: commits_by_id.get(i.data['commit'])
                for i in item_list if i.type == Activity.SET_RESOLVED_IN_COMMIT
            }
        else:
            commits = {}

        groups = apply_values(
            functools.partial(serialize, user=user),
            Group.objects.in_bulk(
                set(i.data['source_id'] for i in item_list
                    if i.type == Activity.UNMERGE_DESTINATION)
                | set(i.data['destination_id'] for i in item_list
                      if i.type == Activity.UNMERGE_SOURCE)))

        return {
            item: {
                'user':
                users[six.text_type(item.user_id)] if item.user_id else None,
                'source':
                groups.get(item.data['source_id'])
                if item.type == Activity.UNMERGE_DESTINATION else None,
                'destination':
                groups.get(item.data['destination_id'])
                if item.type == Activity.UNMERGE_SOURCE else None,
                'commit':
                commits.get(item),
            }
            for item in item_list
        }
예제 #7
0
    def get(self, request, group):
        # TODO(tkaemming): This should have a limit somewhere.
        results = filter(lambda (group_id, scores): group_id != group.id,
                         features.query(group))

        serialized_groups = apply_values(
            functools.partial(serialize, user=request.user),
            Group.objects.in_bulk([group_id for group_id, scores in results]))

        # TODO(tkaemming): This should log when we filter out a group that is
        # unable to be retrieved from the database. (This will soon be
        # unexpected behavior, but still possible.)
        return Response(
            filter(
                lambda (group_id, scores): group_id is not None,
                map(
                    lambda (group_id, scores): (
                        serialized_groups.get(group_id),
                        scores,
                    ),
                    results,
                ),
            ), )