Feat: Filter matching events in reverse order (#6485)

This commit is contained in:
Rohit Malhotra 2025-01-27 17:53:16 -05:00 committed by GitHub
parent 0ba96ce69e
commit 94a64a47f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -367,6 +367,7 @@ class EventStream:
end_date: str | None = None,
start_id: int = 0,
limit: int = 100,
reverse: bool = False,
) -> list:
"""Get matching events from the event stream based on filters.
@ -378,6 +379,7 @@ class EventStream:
end_date: Filter events before this date (ISO format)
start_id: Starting ID in the event stream. Defaults to 0
limit: Maximum number of events to return. Must be between 1 and 100. Defaults to 100
reverse: Whether to retrieve events in reverse order. Defaults to False.
Returns:
list: List of matching events (as dicts)
@ -390,7 +392,7 @@ class EventStream:
matching_events: list = []
for event in self.get_events(start_id=start_id):
for event in self.get_events(start_id=start_id, reverse=reverse):
if self._should_filter_event(
event, query, event_types, source, start_date, end_date
):

View File

@ -89,6 +89,10 @@ def test_get_matching_events_type_filter(temp_dir: str):
events = event_stream.get_matching_events(event_types=(NullAction, MessageAction))
assert len(events) == 3
# Filter in reverse
events = event_stream.get_matching_events(reverse=True, limit=1)
assert events[0]['message'] == 'test'
def test_get_matching_events_query_search(temp_dir: str):
file_store = get_file_store('local', temp_dir)