Skip to content

Commit

Permalink
Utilize scalar selectables to obtain stats
Browse files Browse the repository at this point in the history
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
  • Loading branch information
candleindark committed May 9, 2024
1 parent 67811ca commit c8afc09
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions datalad_registry/blueprints/api/dataset_urls/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c8afc09

Please sign in to comment.