Add LRU to ES fqn (#9233)

This commit is contained in:
Ayush Shah 2022-12-12 12:16:15 +05:30 committed by GitHub
parent 0963eac48e
commit 2e1fb96751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ Mixin class containing Lineage specific methods
To be used by OpenMetadata class
"""
import functools
import traceback
from typing import Generic, List, Optional, Type, TypeVar
@ -38,6 +39,7 @@ class ESMixin(Generic[T]):
fqdn_search = "/search/query?q=fullyQualifiedName:{fqn}&from={from_}&size={size}&index={index}"
@functools.lru_cache()
def _search_es_entity(
self, entity_type: Type[T], query_string: str
) -> Optional[List[T]]:
@ -47,13 +49,13 @@ class ESMixin(Generic[T]):
:param query_string: Query to run
:return: List of Entities or None
"""
response = self.client.get(query_string)
if response:
return [
self.get_by_name(
entity=entity_type, fqn=hit["_source"]["fullyQualifiedName"]
entity=entity_type,
fqn=hit["_source"]["fullyQualifiedName"],
)
for hit in response["hits"]["hits"]
] or None
@ -84,12 +86,10 @@ class ESMixin(Generic[T]):
)
try:
entity_list = self._search_es_entity(
response = self._search_es_entity(
entity_type=entity_type, query_string=query_string
)
if entity_list:
return entity_list
return response
except KeyError as err:
logger.debug(traceback.format_exc())
logger.warning(