kopia lustrzana https://github.com/bugout-dev/moonstream
Fixed issue with previous and next event handlers in BugoutEventProvider
rodzic
36fb761e12
commit
2fbb0a3c7b
|
@ -85,8 +85,11 @@ class BugoutEventProvider:
|
|||
|
||||
If None is returned, signals that no data should be returned from the provider at all.
|
||||
"""
|
||||
is_query_constrained = query.subscription_types or query.subscriptions
|
||||
relevant_subscriptions = user_subscriptions.get(self.event_type)
|
||||
if not relevant_subscriptions:
|
||||
if (
|
||||
is_query_constrained and self.event_type not in query.subscription_types
|
||||
) or not relevant_subscriptions:
|
||||
return None
|
||||
return []
|
||||
|
||||
|
@ -216,7 +219,7 @@ class BugoutEventProvider:
|
|||
)
|
||||
if not search_results.results:
|
||||
return None
|
||||
return search_results.results[0]
|
||||
return self.entry_event(search_results.results[0])
|
||||
|
||||
def previous_event(
|
||||
self,
|
||||
|
@ -258,7 +261,7 @@ class BugoutEventProvider:
|
|||
)
|
||||
if not search_results.results:
|
||||
return None
|
||||
return search_results.results[0]
|
||||
return self.entry_event(search_results.results[0])
|
||||
|
||||
|
||||
whalewatch_provider = BugoutEventProvider(
|
||||
|
|
|
@ -15,6 +15,7 @@ from sqlalchemy.sql.functions import user
|
|||
|
||||
from .. import data
|
||||
from ..settings import DEFAULT_STREAM_TIMEINTERVAL
|
||||
from ..stream_boundaries import validate_stream_boundary
|
||||
from ..stream_queries import StreamQuery
|
||||
|
||||
|
||||
|
@ -47,6 +48,20 @@ def validate_subscription(
|
|||
return True, errors
|
||||
|
||||
|
||||
def stream_boundary_validator(stream_boundary: data.StreamBoundary) -> None:
|
||||
"""
|
||||
Stream boundary validator for the ethereum_blockchain event provider.
|
||||
|
||||
Checks that stream boundaries do not exceed periods of greater than 2 hours.
|
||||
|
||||
Raises an error for invalid stream boundaries, else returns None.
|
||||
"""
|
||||
valid_period_seconds = 2 * 60 * 60
|
||||
validate_stream_boundary(
|
||||
stream_boundary, valid_period_seconds, raise_when_invalid=True
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Filters:
|
||||
"""
|
||||
|
@ -233,6 +248,8 @@ def get_events(
|
|||
|
||||
If the query does not require any data from this provider, returns None.
|
||||
"""
|
||||
stream_boundary_validator(stream_boundary)
|
||||
|
||||
parsed_filters = parse_filters(query, user_subscriptions)
|
||||
if parsed_filters is None:
|
||||
return None
|
||||
|
|
Ładowanie…
Reference in New Issue