Пример #1
0
def get_project_issues(project_ids, issue_ids=None):
    """
    Get a list of issues and associated fingerprint hashes for a list of
    project ids. If issue_ids is set, then return only those issues.

    Returns a list: [(group_id, project_id, [(hash1, tomestone_date), ...]), ...]
    """
    if issue_ids:
        issue_ids = issue_ids[:MAX_ISSUES]
        hashes = GroupHash.objects.filter(
            group_id__in=issue_ids
        )[:MAX_HASHES]
    else:
        hashes = GroupHash.objects.filter(
            project__in=project_ids,
            group_id__isnull=False,
        )[:MAX_HASHES]

    hashes = [h for h in hashes if HASH_RE.match(h.hash)]
    if not hashes:
        return []

    hashes_by_project = {}
    for h in hashes:
        hashes_by_project.setdefault(h.project_id, []).append(h.hash)

    tombstones = GroupHashTombstone.objects.filter(
        reduce(or_, (Q(project_id=pid, hash__in=hshes)
                     for pid, hshes in six.iteritems(hashes_by_project)))
    )

    tombstones_by_project = {}
    for tombstone in tombstones:
        tombstones_by_project.setdefault(
            tombstone.project_id, {}
        )[tombstone.hash] = tombstone.deleted_at

    # return [(gid, pid, [(hash, tombstone_date), (hash, tombstone_date), ...]), ...]
    result = {}
    for h in hashes:
        tombstone_date = tombstones_by_project.get(h.project_id, {}).get(h.hash, None)
        pair = (
            h.hash,
            tombstone_date.strftime("%Y-%m-%d %H:%M:%S") if tombstone_date else None
        )
        result.setdefault((h.group_id, h.project_id), []).append(pair)
    return [k + (v,) for k, v in result.items()][:MAX_ISSUES]
Пример #2
0
def get_project_issues(project_ids, issue_ids=None):
    """
    Get a list of issues and associated fingerprint hashes for a list of
    project ids. If issue_ids is set, then return only those issues.

    Returns a list: [(issue_id: [hash1, hash2, ...]), ...]
    """
    if issue_ids:
        issue_ids = issue_ids[:MAX_ISSUES]
        hashes = GroupHash.objects.filter(
            group_id__in=issue_ids
        )[:MAX_HASHES]
    else:
        hashes = GroupHash.objects.filter(
            project__in=project_ids,
            group_id__isnull=False,
        )[:MAX_HASHES]

    hashes = [h for h in hashes if HASH_RE.match(h.hash)]
    if not hashes:
        return []

    hashes_by_project = {}
    for h in hashes:
        hashes_by_project.setdefault(h.project_id, []).append(h.hash)

    tombstones = GroupHashTombstone.objects.filter(
        reduce(or_, (Q(project_id=pid, hash__in=hshes)
                     for pid, hshes in six.iteritems(hashes_by_project)))
    )

    tombstones_by_project = {}
    for tombstone in tombstones:
        tombstones_by_project.setdefault(
            tombstone.project_id, {}
        )[tombstone.hash] = tombstone.deleted_at

    # return [(gid, pid, [(hash, tombstone_date), (hash, tombstone_date), ...]), ...]
    result = {}
    for h in hashes:
        tombstone_date = tombstones_by_project.get(h.project_id, {}).get(h.hash, None)
        pair = (
            h.hash,
            tombstone_date.strftime("%Y-%m-%d %H:%M:%S") if tombstone_date else None
        )
        result.setdefault((h.group_id, h.project_id), []).append(pair)
    return [k + (v,) for k, v in result.items()][:MAX_ISSUES]
Пример #3
0
def get_project_issues(project_ids, issue_ids=None):
    """
    Get a list of issues and associated fingerprint hashes for a list of
    project ids. If issue_ids is set, then return only those issues.

    Returns a list: [(issue_id: [hash1, hash2, ...]), ...]
    """
    if issue_ids:
        # TODO remove this when Snuba accepts more than 500 issues
        issue_ids = issue_ids[:500]
        hashes = GroupHash.objects.filter(group_id__in=issue_ids)
    else:
        hashes = GroupHash.objects.filter(project__in=project_ids)

    hashes = [h for h in hashes if HASH_RE.match(h.hash)]
    if not hashes:
        return []

    hashes_by_project = {}
    for h in hashes:
        hashes_by_project.setdefault(h.project_id, []).append(h.hash)

    tombstones = GroupHashTombstone.objects.filter(
        reduce(or_, (Q(project_id=pid, hash__in=hshes)
                    for pid, hshes in six.iteritems(hashes_by_project)))
    )

    tombstones_by_project = {}
    for tombstone in tombstones:
        tombstones_by_project.setdefault(
            tombstone.project_id, {}
        )[tombstone.hash] = tombstone.deleted_at

    # return [(gid, [(hash, tombstone_date), (hash, tombstone_date), ...]), ...]
    result = {}
    for h in hashes:
        tombstone_date = tombstones_by_project.get(h.project_id, {}).get(h.hash, None)
        pair = (h.hash, tombstone_date.strftime("%Y-%m-%d %H:%M:%S") if tombstone_date else None)
        result.setdefault(h.group_id, []).append(pair)
    return list(result.items())