Ejemplo n.º 1
0
def get_latest_events(group_hash_list):
    """
    Fetch the latest events for a collection of ``GroupHash`` instances.
    Returns a list of events (or ``None``) in the same order as the input
    sequence.
    """
    group_hashes_by_project_id = defaultdict(list)
    for group_hash in group_hash_list:
        group_hashes_by_project_id[group_hash.project_id].append(group_hash)

    events_by_group_hash = {}
    for project_id, group_hash_list_chunk in group_hashes_by_project_id.items(
    ):
        event_id_list = GroupHash.fetch_last_processed_event_id(
            [i.id for i in group_hash_list_chunk])
        event_by_event_id = {
            event.event_id: event
            for event in Event.objects.filter(
                project_id=project_id,
                event_id__in=filter(None, event_id_list),
            )
        }
        for group_hash, event_id in zip(group_hash_list_chunk, event_id_list):
            event = event_by_event_id.get(event_id)
            if event is not None and event.group_id == group_hash.group_id:
                events_by_group_hash[group_hash] = event

    return [
        events_by_group_hash.get(group_hash) for group_hash in group_hash_list
    ]
Ejemplo n.º 2
0
def get_latest_events(group_hash_list):
    """
    Fetch the latest events for a collection of ``GroupHash`` instances.
    Returns a list of events (or ``None``) in the same order as the input
    sequence.
    """
    group_hashes_by_project_id = defaultdict(list)
    for group_hash in group_hash_list:
        group_hashes_by_project_id[group_hash.project_id].append(group_hash)

    events_by_group_hash = {}
    for project_id, group_hash_list_chunk in group_hashes_by_project_id.items():
        event_id_list = GroupHash.fetch_last_processed_event_id(
            [i.id for i in group_hash_list_chunk])
        event_by_event_id = {
            event.event_id: event
            for event in Event.objects.filter(
                project_id=project_id,
                event_id__in=filter(None, event_id_list),
            )
        }
        for group_hash, event_id in zip(group_hash_list_chunk, event_id_list):
            event = event_by_event_id.get(event_id)
            if event is not None and event.group_id == group_hash.group_id:
                events_by_group_hash[group_hash] = event

    return [events_by_group_hash.get(group_hash) for group_hash in group_hash_list]
Ejemplo n.º 3
0
    def test_fetch_and_record_last_processed_event_id(self):
        group = self.group

        grouphash = GroupHash.objects.create(
            project=group.project,
            group=group,
            hash='xyz',
        )

        GroupHash.record_last_processed_event_id(
            grouphash.id,
            'event',
        )

        assert GroupHash.fetch_last_processed_event_id(
            [grouphash.id, -1],
        ) == ['event', None]