|
18 | 18 | from pydantic.alias_generators import to_camel as to_lower_camel
|
19 | 19 | from sqlalchemy import Select, func, select
|
20 | 20 | from sqlalchemy.orm import contains_eager
|
| 21 | +from starlette.concurrency import run_in_threadpool |
21 | 22 | from strawberry.experimental.pydantic.conversion_types import StrawberryTypeFromPydantic
|
22 | 23 |
|
23 | 24 | from nwastdlib.asyncio import gather_nice
|
@@ -101,7 +102,7 @@ async def format_subscription(info: OrchestratorInfo, subscription: Subscription
|
101 | 102 | async def resolve_subscription(info: OrchestratorInfo, id: UUID) -> SubscriptionInterface | None:
|
102 | 103 | stmt = select(SubscriptionTable).where(SubscriptionTable.subscription_id == id)
|
103 | 104 |
|
104 |
| - if subscription := db.session.scalar(stmt): |
| 105 | + if subscription := await run_in_threadpool(db.session.scalar, stmt): |
105 | 106 | return await format_subscription(info, subscription)
|
106 | 107 | return None
|
107 | 108 |
|
@@ -141,12 +142,13 @@ async def resolve_subscriptions(
|
141 | 142 | stmt = filter_by_query_string(stmt, query)
|
142 | 143 |
|
143 | 144 | stmt = cast(Select, sort_subscriptions(stmt, pydantic_sort_by, _error_handler))
|
144 |
| - total = db.session.scalar(select(func.count()).select_from(stmt.subquery())) |
| 145 | + total = await run_in_threadpool(db.session.scalar, select(func.count()).select_from(stmt.subquery())) |
145 | 146 | stmt = apply_range_to_statement(stmt, after, after + first + 1)
|
146 | 147 |
|
147 | 148 | graphql_subscriptions: list[SubscriptionInterface] = []
|
148 | 149 | if is_querying_page_data(info):
|
149 |
| - subscriptions = db.session.scalars(stmt).all() |
| 150 | + scalars = await run_in_threadpool(db.session.scalars, stmt) |
| 151 | + subscriptions = scalars.all() |
150 | 152 | graphql_subscriptions = list(await gather_nice((format_subscription(info, p) for p in subscriptions))) # type: ignore
|
151 | 153 | logger.info("Resolve subscriptions", filter_by=filter_by, total=total)
|
152 | 154 |
|
|
0 commit comments