From c8afc09c02696b1d56c6390b73f34305f85d8831 Mon Sep 17 00:00:00 2001 From: Isaac To Date: Thu, 9 May 2024 11:49:22 -0700 Subject: [PATCH] Utilize scalar selectables to obtain stats Instead of executing a selectable in a function. Returning a scalar selectable allow the stats to be obtained through execution of a single query containing many subqueries --- .../blueprints/api/dataset_urls/tools.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/datalad_registry/blueprints/api/dataset_urls/tools.py b/datalad_registry/blueprints/api/dataset_urls/tools.py index 3e40ff18..ad79127f 100644 --- a/datalad_registry/blueprints/api/dataset_urls/tools.py +++ b/datalad_registry/blueprints/api/dataset_urls/tools.py @@ -200,12 +200,15 @@ def get_non_annex_ds_collection_stats(base_cte: CTE) -> ScalarSelect: .subquery("non_annex_ds_q") ) - return select( - func.jsonb_build_object( - "ds_count", - select(func.count()).select_from(non_annex_ds_q).scalar_subquery(), - ).label("non_annex_ds_collection_stats") - ).scalar_subquery() + return ( + select( + func.jsonb_build_object("ds_count", func.count()).label( + "non_annex_ds_collection_stats" + ) + ) + .select_from(non_annex_ds_q) + .scalar_subquery() + ) def get_collection_stats(select_stmt: Select) -> CollectionStats: