1
0
mirror of synced 2026-01-05 21:02:13 -05:00

🐛 Source Intercom: Fix conversations incremental pagination slowness (#11208)

This commit is contained in:
Brian Krausz
2022-03-21 09:14:56 -04:00
committed by GitHub
parent 94a862bbbe
commit ea92a24da3
7 changed files with 20 additions and 6 deletions

View File

@@ -92,6 +92,10 @@ class IntercomStream(HttpStream, ABC):
class IncrementalIntercomStream(IntercomStream, ABC):
cursor_field = "updated_at"
def __init__(self, authenticator: AuthBase, start_date: str = None, **kwargs):
super().__init__(authenticator, start_date, **kwargs)
self.has_old_records = False
def filter_by_state(self, stream_state: Mapping[str, Any] = None, record: Mapping[str, Any] = None) -> Iterable:
"""
Endpoint does not provide query filtering params, but they provide us
@@ -101,6 +105,8 @@ class IncrementalIntercomStream(IntercomStream, ABC):
if not stream_state or record[self.cursor_field] > stream_state.get(self.cursor_field):
yield record
else:
self.has_old_records = True
def parse_response(self, response: requests.Response, stream_state: Mapping[str, Any], **kwargs) -> Iterable[Mapping]:
record = super().parse_response(response, stream_state, **kwargs)
@@ -282,9 +288,16 @@ class Conversations(IncrementalIntercomStream):
def request_params(self, next_page_token: Mapping[str, Any] = None, **kwargs) -> MutableMapping[str, Any]:
params = super().request_params(next_page_token, **kwargs)
params.update({"order": "asc", "sort": self.cursor_field})
params.update({"order": "desc", "sort": self.cursor_field})
return params
# We're sorting by desc. Once we hit the first page with an out-of-date result we can stop.
def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
if self.has_old_records:
return None
return super().next_page_token(response)
def path(self, **kwargs) -> str:
return "conversations"