From 08ac9f4cfd0cd93a36f98ce72adeb58ff0c4b9ed Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:59:09 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Speed=20up=20method=20`Tim?= =?UTF-8?q?er.finish`=20by=2047%=20in=20PR=20#45125=20(`tolik0/airbyte-cdk?= =?UTF-8?q?/add-per-partition-with-global-fallback`)=20To=20optimize=20the?= =?UTF-8?q?=20given=20Python=20program,=20we=20can=20make=20the=20followin?= =?UTF-8?q?g=20changes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../declarative/incremental/global_substream_cursor.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/airbyte-cdk/python/airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py b/airbyte-cdk/python/airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py index d905a74f774d..045cf366cf2c 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py @@ -54,10 +54,12 @@ def start(self) -> None: self._start = time.perf_counter_ns() def finish(self) -> int: - if self._start: - return ((time.perf_counter_ns() - self._start) / 1e9).__ceil__() - else: - raise RuntimeError("Global substream cursor timer not started") + start_time = self._start + if start_time is None: + raise RuntimeError("Timer not started") + + elapsed_ns = time.perf_counter_ns() - start_time + return -(-elapsed_ns // 1_000_000_000) class GlobalSubstreamCursor(DeclarativeCursor):