diff --git a/src/app/api/analytics/background_task.py b/src/app/api/analytics/background_task.py index 40cf936..e4df0d5 100644 --- a/src/app/api/analytics/background_task.py +++ b/src/app/api/analytics/background_task.py @@ -21,7 +21,6 @@ _COLLECTIONS, _MATERIALS, SearchStore, - SearchStoreCollection, global_store, ) from app.api.collections.counts import AggregationMappings, collection_counts @@ -128,15 +127,13 @@ def run(): for row in all_collections: sub_collections: list[Row] = asyncio.run(get_ids_to_iterate(node_id=row.id)) print("Working on: ", row.title, len(sub_collections)) - collections = { - sub.id: SearchStoreCollection( - node_id=sub.id, - missing_materials=search_hits_by_material_type(sub.title), - ) - for sub in sub_collections + missing_materials = { + sub.id: search_hits_by_material_type(sub.title) for sub in sub_collections } - search_store.append(SearchStore(node_id=row.id, collections=collections)) + search_store.append( + SearchStore(node_id=row.id, missing_materials=missing_materials) + ) global_store.search = search_store diff --git a/src/app/api/analytics/stats.py b/src/app/api/analytics/stats.py index 5b434f7..775c566 100644 --- a/src/app/api/analytics/stats.py +++ b/src/app/api/analytics/stats.py @@ -87,7 +87,7 @@ def search_hits_by_material_type(collection_title: str) -> dict: response: Response = s[:0].execute() if response.success(): - # TODO: Clear and cleanu p: what does this do? + # TODO: Clear and cleanup: what does this do? stats = merge_agg_response(response.aggregations.material_types) stats["total"] = sum(stats.values()) return stats @@ -182,10 +182,7 @@ async def query_search_statistics( ) -> dict[str, CountStatistics]: for stats in global_store.search: if str(node_id) == str(stats.node_id): - return { - str(key): value.missing_materials - for key, value in stats.collections.items() - } + return {str(key): value for key, value in stats.missing_materials.items()} return {} diff --git a/src/app/api/analytics/storage.py b/src/app/api/analytics/storage.py index 5bb90e1..5af58b1 100644 --- a/src/app/api/analytics/storage.py +++ b/src/app/api/analytics/storage.py @@ -19,20 +19,14 @@ } # TODO: Refactor me ASAP -@dataclass(frozen=True) -class SearchStoreCollection: - node_id: uuid.UUID - missing_materials: CountStatistics - - @dataclass(frozen=True) class SearchStore: - __slots__ = "node_id", "collections" + __slots__ = "node_id", "missing_materials" node_id: uuid.UUID - collections: dict[uuid.UUID, SearchStoreCollection] + missing_materials: dict[uuid.UUID, CountStatistics] -@dataclass(frozen=True) +@dataclass(frozen=False) class Store: __slots__ = "search" search: list[SearchStore] diff --git a/tests/test_stats.py b/tests/test_stats.py index d041328..34bba34 100644 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -14,7 +14,7 @@ overall_stats, query_material_types, ) -from app.api.analytics.storage import SearchStore, SearchStoreCollection +from app.api.analytics.storage import SearchStore from app.api.collections.counts import CollectionTreeCount @@ -52,10 +52,8 @@ def _get_item(_, key): return [ SearchStore( node_id=uuid.UUID(test_node), - collections={ - key: SearchStoreCollection( - node_id=key, missing_materials=item["missing_materials"] - ) + missing_materials={ + key: item["missing_materials"] for key, item in entry["collections"].items() }, )