From bfb3224684efb203bb14d94526e15e541f34e3a9 Mon Sep 17 00:00:00 2001 From: Farajollahi Date: Thu, 6 Aug 2026 18:38:35 +0200 Subject: [PATCH] Revert "fix bug" This reverts commit d48435b948f794468480eeda3c3278f19b44186b. --- service/src/main/inse/dashboard/service.py | 26 ++----------------- .../src/main/inse/dashboard/test_service.py | 14 +++------- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/service/src/main/inse/dashboard/service.py b/service/src/main/inse/dashboard/service.py index 640cfb7b..c1f55565 100644 --- a/service/src/main/inse/dashboard/service.py +++ b/service/src/main/inse/dashboard/service.py @@ -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"])) diff --git a/service/src/main/inse/dashboard/test_service.py b/service/src/main/inse/dashboard/test_service.py index 049a488c..85cc9c1a 100644 --- a/service/src/main/inse/dashboard/test_service.py +++ b/service/src/main/inse/dashboard/test_service.py @@ -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}], + } } ] },