mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-09 17:12:02 +00:00
Add LRU to ES fqn (#9233)
This commit is contained in:
parent
0963eac48e
commit
2e1fb96751
@ -13,6 +13,7 @@ Mixin class containing Lineage specific methods
|
|||||||
|
|
||||||
To be used by OpenMetadata class
|
To be used by OpenMetadata class
|
||||||
"""
|
"""
|
||||||
|
import functools
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Generic, List, Optional, Type, TypeVar
|
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}"
|
fqdn_search = "/search/query?q=fullyQualifiedName:{fqn}&from={from_}&size={size}&index={index}"
|
||||||
|
|
||||||
|
@functools.lru_cache()
|
||||||
def _search_es_entity(
|
def _search_es_entity(
|
||||||
self, entity_type: Type[T], query_string: str
|
self, entity_type: Type[T], query_string: str
|
||||||
) -> Optional[List[T]]:
|
) -> Optional[List[T]]:
|
||||||
@ -47,13 +49,13 @@ class ESMixin(Generic[T]):
|
|||||||
:param query_string: Query to run
|
:param query_string: Query to run
|
||||||
:return: List of Entities or None
|
:return: List of Entities or None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
response = self.client.get(query_string)
|
response = self.client.get(query_string)
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
return [
|
return [
|
||||||
self.get_by_name(
|
self.get_by_name(
|
||||||
entity=entity_type, fqn=hit["_source"]["fullyQualifiedName"]
|
entity=entity_type,
|
||||||
|
fqn=hit["_source"]["fullyQualifiedName"],
|
||||||
)
|
)
|
||||||
for hit in response["hits"]["hits"]
|
for hit in response["hits"]["hits"]
|
||||||
] or None
|
] or None
|
||||||
@ -84,12 +86,10 @@ class ESMixin(Generic[T]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
entity_list = self._search_es_entity(
|
response = self._search_es_entity(
|
||||||
entity_type=entity_type, query_string=query_string
|
entity_type=entity_type, query_string=query_string
|
||||||
)
|
)
|
||||||
if entity_list:
|
return response
|
||||||
return entity_list
|
|
||||||
|
|
||||||
except KeyError as err:
|
except KeyError as err:
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user