Skip to content

Commit 7df4f5c

Browse files
committed
cleanup
1 parent 5d9fc81 commit 7df4f5c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

services/web/server/src/simcore_service_webserver/folders/_folders_repository.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from datetime import datetime
3-
from typing import cast
3+
from typing import Callable, cast
44

55
import sqlalchemy as sa
66
from aiohttp import web
@@ -160,11 +160,11 @@ def _set_ordering(
160160
base_query: GenerativeSelect,
161161
order_by: OrderBy,
162162
) -> GenerativeSelect:
163-
if order_by.direction == OrderDirection.ASC:
164-
list_query = base_query.order_by(asc(getattr(folders_v2.c, order_by.field)))
165-
else:
166-
list_query = base_query.order_by(desc(getattr(folders_v2.c, order_by.field)))
167-
return list_query
163+
direction_func: Callable = {OrderDirection.ASC: asc, OrderDirection: desc}[
164+
order_by.direction
165+
]
166+
column = getattr(folders_v2.c, order_by.field)
167+
return base_query.order_by(direction_func(column))
168168

169169

170170
async def list_( # pylint: disable=too-many-arguments,too-many-branches
@@ -247,8 +247,9 @@ async def list_( # pylint: disable=too-many-arguments,too-many-branches
247247
count_query = select(func.count()).select_from(combined_query.subquery())
248248

249249
# Ordering and pagination
250-
list_query = _set_ordering(combined_query, order_by=order_by)
251-
list_query = list_query.offset(offset).limit(limit)
250+
list_query = (
251+
_set_ordering(combined_query, order_by=order_by).offset(offset).limit(limit)
252+
)
252253

253254
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
254255
total_count = await conn.scalar(count_query)
@@ -293,8 +294,7 @@ async def list_trashed_folders(
293294
count_query = select(func.count()).select_from(base_query.subquery())
294295

295296
# Ordering and pagination
296-
list_query = _set_ordering(base_query, order_by)
297-
list_query = list_query.offset(offset).limit(limit)
297+
list_query = _set_ordering(base_query, order_by).offset(offset).limit(limit)
298298

299299
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
300300
total_count = await conn.scalar(count_query)

0 commit comments

Comments
 (0)