Skip to content

Commit 071563d

Browse files
committed
Fix cyclic dependency between clients and sub clients
While the Python GC can handle those dependencies, it can cause latency spikes when .option() is used for each query, which causes a lot of clients to be garbage collected.
1 parent 7ae3235 commit 071563d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

elasticsearch/_async/client/_base.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _default_sniffed_node_callback(
209209
)
210210

211211

212-
class BaseClient:
212+
class TransportClient:
213213
def __init__(self, _transport: AsyncTransport) -> None:
214214
self._transport = _transport
215215
self._client_meta: Union[DefaultType, Tuple[Tuple[str, str], ...]] = DEFAULT
@@ -376,7 +376,12 @@ def mimetype_header_to_compat(header: str) -> None:
376376
return response
377377

378378

379-
class NamespacedClient(BaseClient):
379+
class BaseClient(TransportClient):
380+
def __init__(self, _transport: AsyncTransport) -> None:
381+
super().__init__(_transport)
382+
383+
384+
class NamespacedClient(TransportClient):
380385
def __init__(self, client: "BaseClient") -> None:
381386
self._client = client
382387
super().__init__(self._client.transport)

elasticsearch/_sync/client/_base.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _default_sniffed_node_callback(
209209
)
210210

211211

212-
class BaseClient:
212+
class TransportClient:
213213
def __init__(self, _transport: Transport) -> None:
214214
self._transport = _transport
215215
self._client_meta: Union[DefaultType, Tuple[Tuple[str, str], ...]] = DEFAULT
@@ -376,7 +376,12 @@ def mimetype_header_to_compat(header: str) -> None:
376376
return response
377377

378378

379-
class NamespacedClient(BaseClient):
379+
class BaseClient(TransportClient):
380+
def __init__(self, _transport: Transport) -> None:
381+
super().__init__(_transport)
382+
383+
384+
class NamespacedClient(TransportClient):
380385
def __init__(self, client: "BaseClient") -> None:
381386
self._client = client
382387
super().__init__(self._client.transport)

0 commit comments

Comments
 (0)