Revert "fix bug"
LocationBasedServices/smartguide/pipeline/head This commit looks good

This reverts commit d48435b948.
This commit is contained in:
2026-08-06 18:38:35 +02:00
parent aed1f33935
commit bfb3224684
2 changed files with 5 additions and 35 deletions
+2 -24
View File
@@ -1454,7 +1454,7 @@ async def get_top_authors(
authors = await _safe_institution_authors(normalized_id)
works = await _safe_top_authors(
"works",
_top_work_authors(normalized_id, period, authors),
_top_work_authors(normalized_id, period),
)
projects = await _safe_top_authors(
"projects",
@@ -1874,16 +1874,7 @@ def _short_author_id(value: str) -> str:
async def _top_work_authors(
institution_id: str,
period: DashboardPeriod,
institution_authors: list[dict[str, Any]],
) -> list[TopAuthor]:
institution_author_ids = {
_short_author_id(str(author["id"]))
for author in institution_authors
if author.get("id")
}
if not institution_author_ids:
return []
must = [works_v2_service._institutions_nested_query([institution_id])]
if publication_years := _dashboard_publication_years(period):
must.append({"terms": {"publication_year": publication_years}})
@@ -1893,30 +1884,17 @@ async def _top_work_authors(
async for hit in elasticsearch.scan(
index=str(ESIndex.OPENALEX_WORKS_WILDCARD),
query={"bool": {"must": must}},
source=[
"id",
"authorships.author.id",
"authorships.author.display_name",
"authorships.institutions.id",
],
source=["id", "authorships.author.id", "authorships.author.display_name"],
page_size=1000,
cluster=ESCluster.NES,
):
hit_author_ids: set[str] = set()
for authorship in hit.get("_source", {}).get("authorships", []):
if not any(
_normalize_institution_id(institution.get("id")) == institution_id
for institution in authorship.get("institutions") or []
if institution.get("id")
):
continue
author = authorship.get("author") or {}
author_id = author.get("id")
if not author_id:
continue
author_id = str(author_id)
if _short_author_id(author_id) not in institution_author_ids:
continue
hit_author_ids.add(author_id)
if author.get("display_name"):
author_names.setdefault(author_id, str(author["display_name"]))
@@ -683,14 +683,12 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
"id": "https://openalex.org/A1",
"display_name": "Ada Example",
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
},
{
"author": {
"id": "https://openalex.org/A2",
"display_name": "Grace Example",
},
"institutions": [{"id": "https://openalex.org/I999"}],
},
],
},
@@ -705,7 +703,6 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
"id": "https://openalex.org/A1",
"display_name": "Ada Example",
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
],
},
@@ -760,7 +757,6 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
"name": "Ada Example",
"count": 2,
}
assert len(result.works) == 1
assert result.patents[0].model_dump() == {
"id": "A1",
"name": "Ada Example",
@@ -823,7 +819,6 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
"id",
"authorships.author.id",
"authorships.author.display_name",
"authorships.institutions.id",
]
eu_work_calls = [
@@ -1132,8 +1127,7 @@ async def test_top_authors_returns_partial_response_when_one_source_fails():
"author": {
"id": "https://openalex.org/A1",
"display_name": "Ada Example",
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
}
],
},
@@ -1221,8 +1215,7 @@ async def test_top_authors_can_rank_works_by_last_five_years():
"author": {
"id": "https://openalex.org/A2",
"display_name": "Grace Example",
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
}
]
},
@@ -1236,8 +1229,7 @@ async def test_top_authors_can_rank_works_by_last_five_years():
"author": {
"id": "https://openalex.org/A1",
"display_name": "Ada Example",
},
"institutions": [{"id": ORG_INSTITUTION_ID}],
}
}
]
},