fix(patents): await async person and co-author lookups after dev merge
LocationBasedServices/smartguide/pipeline/pr-dev This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev This commit looks good
This commit is contained in:
@@ -41,7 +41,7 @@ async def get_patents_by_author_id(
|
||||
search_client = client or PatentSearchClient()
|
||||
ipc_search_client = ipc_client or IpcSearchClient()
|
||||
|
||||
author = _get_author(author_id)
|
||||
author = await _get_author(author_id)
|
||||
if not author:
|
||||
return model.PatentsByAuthorResponse(
|
||||
author_id=author_id,
|
||||
@@ -86,7 +86,7 @@ async def get_patents_by_author_id(
|
||||
|
||||
all_patents = deduplicate_patents(all_patents)
|
||||
|
||||
profile = build_author_profile(
|
||||
profile = await build_author_profile(
|
||||
author,
|
||||
patent_hit_count=patent_hit_count,
|
||||
)
|
||||
@@ -141,7 +141,7 @@ def _filter_patents_by_last_name(
|
||||
]
|
||||
|
||||
|
||||
def _get_author(author_id: str) -> Author | None:
|
||||
async def _get_author(author_id: str) -> Author | None:
|
||||
short_id = author_id.replace("https://openalex.org/", "")
|
||||
result = person_logic.search_persons(author_id=short_id)
|
||||
result = await person_logic.search_persons(author_id=short_id)
|
||||
return result.results[0] if result.results else None
|
||||
|
||||
@@ -93,7 +93,7 @@ def _author_topics(author: Author) -> list[AuthorTopic]:
|
||||
return topics[:15]
|
||||
|
||||
|
||||
def _fetch_co_author_names(author_id: str, display_name: str) -> list[str]:
|
||||
async def _fetch_co_author_names(author_id: str, display_name: str) -> list[str]:
|
||||
short_id = _normalize_author_id(author_id)
|
||||
author_url = f"https://openalex.org/{short_id}"
|
||||
normalized_self = display_name.casefold().strip()
|
||||
@@ -115,7 +115,7 @@ def _fetch_co_author_names(author_id: str, display_name: str) -> list[str]:
|
||||
}
|
||||
|
||||
try:
|
||||
response = elasticsearch.search(
|
||||
response = await elasticsearch.search(
|
||||
index=config.settings.openalex_works_search_index,
|
||||
body=body,
|
||||
)
|
||||
@@ -141,7 +141,7 @@ def _fetch_co_author_names(author_id: str, display_name: str) -> list[str]:
|
||||
return co_authors[:40]
|
||||
|
||||
|
||||
def build_author_profile(
|
||||
async def build_author_profile(
|
||||
author: Author,
|
||||
*,
|
||||
patent_hit_count: int | None = None,
|
||||
@@ -154,7 +154,7 @@ def build_author_profile(
|
||||
|
||||
co_author_names: list[str] = []
|
||||
if fetch_co_authors and author_id:
|
||||
co_author_names = _fetch_co_author_names(author_id, display_name)
|
||||
co_author_names = await _fetch_co_author_names(author_id, display_name)
|
||||
|
||||
return AuthorProfile(
|
||||
author_id=author_id,
|
||||
|
||||
@@ -315,7 +315,7 @@ async def _search_patents_by_author(
|
||||
patents = deduplicate_patents(patents)
|
||||
|
||||
patent_hit_count = parse_search_total(epo_data) + parse_search_total(uspto_data)
|
||||
profile = build_author_profile(author, patent_hit_count=patent_hit_count)
|
||||
profile = await build_author_profile(author, patent_hit_count=patent_hit_count)
|
||||
matched_patents = disambiguate_patents(patents, profile)
|
||||
return [patent_from_matched(entry) for entry in matched_patents]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user