Skip to content

Commit d6a0f26

Browse files
committed
cleanup _services_sql free functions use
1 parent e281686 commit d6a0f26

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

services/catalog/src/simcore_service_catalog/repository/_services_sql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _has_access_rights(
116116
)
117117

118118

119-
def _apply_services_filters(
119+
def apply_services_filters(
120120
stmt: sa.sql.Select,
121121
filters: ServiceFiltersDB,
122122
) -> sa.sql.Select:
@@ -180,7 +180,7 @@ def latest_services_total_count_stmt(
180180
)
181181

182182
if filters:
183-
stmt = _apply_services_filters(stmt, filters)
183+
stmt = apply_services_filters(stmt, filters)
184184

185185
return stmt
186186

@@ -224,7 +224,7 @@ def list_latest_services_stmt(
224224
)
225225

226226
if filters:
227-
cte_stmt = _apply_services_filters(cte_stmt, filters)
227+
cte_stmt = apply_services_filters(cte_stmt, filters)
228228

229229
cte = cte_stmt.cte("cte")
230230

services/catalog/src/simcore_service_catalog/repository/services.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,11 @@
4343
ServiceWithHistoryDBGet,
4444
)
4545
from ..models.services_specifications import ServiceSpecificationsAtDB
46+
from . import _services_sql
4647
from ._base import BaseRepository
4748
from ._services_sql import (
4849
SERVICES_META_DATA_COLS,
4950
AccessRightsClauses,
50-
_apply_services_filters,
51-
by_version,
52-
can_get_service_stmt,
53-
get_service_history_stmt,
54-
get_service_stmt,
55-
latest_services_total_count_stmt,
56-
list_latest_services_stmt,
57-
list_services_stmt,
5851
)
5952

6053
_logger = logging.getLogger(__name__)
@@ -101,7 +94,7 @@ async def list_services(
10194
return [
10295
ServiceMetaDataDBGet.model_validate(row)
10396
async for row in await conn.stream(
104-
list_services_stmt(
97+
_services_sql.list_services_stmt(
10598
gids=gids,
10699
execute_access=execute_access,
107100
write_access=write_access,
@@ -295,7 +288,7 @@ async def can_get_service(
295288
"""Returns False if it cannot get the service i.e. not found or does not have access"""
296289
async with self.db_engine.begin() as conn:
297290
result = await conn.execute(
298-
can_get_service_stmt(
291+
_services_sql.can_get_service_stmt(
299292
product_name=product_name,
300293
user_id=user_id,
301294
access_rights=AccessRightsClauses.can_read,
@@ -316,7 +309,7 @@ async def can_update_service(
316309
) -> bool:
317310
async with self.db_engine.begin() as conn:
318311
result = await conn.execute(
319-
can_get_service_stmt(
312+
_services_sql.can_get_service_stmt(
320313
product_name=product_name,
321314
user_id=user_id,
322315
access_rights=AccessRightsClauses.can_edit,
@@ -336,7 +329,7 @@ async def get_service_with_history(
336329
version: ServiceVersion,
337330
) -> ServiceWithHistoryDBGet | None:
338331

339-
stmt_get = get_service_stmt(
332+
stmt_get = _services_sql.get_service_stmt(
340333
product_name=product_name,
341334
user_id=user_id,
342335
access_rights=AccessRightsClauses.can_read,
@@ -349,7 +342,7 @@ async def get_service_with_history(
349342
row = result.one_or_none()
350343

351344
if row:
352-
stmt_history = get_service_history_stmt(
345+
stmt_history = _services_sql.get_service_history_stmt(
353346
product_name=product_name,
354347
user_id=user_id,
355348
access_rights=AccessRightsClauses.can_read,
@@ -396,13 +389,13 @@ async def list_latest_services(
396389
) -> tuple[PositiveInt, list[ServiceWithHistoryDBGet]]:
397390

398391
# get page
399-
stmt_total = latest_services_total_count_stmt(
392+
stmt_total = _services_sql.latest_services_total_count_stmt(
400393
product_name=product_name,
401394
user_id=user_id,
402395
access_rights=AccessRightsClauses.can_read,
403396
filters=filters,
404397
)
405-
stmt_page = list_latest_services_stmt(
398+
stmt_page = _services_sql.list_latest_services_stmt(
406399
product_name=product_name,
407400
user_id=user_id,
408401
access_rights=AccessRightsClauses.can_read,
@@ -459,7 +452,7 @@ async def get_service_history(
459452
"""
460453
DEPRECATED: use get_service_history_page instead!
461454
"""
462-
stmt_history = get_service_history_stmt(
455+
stmt_history = _services_sql.get_service_history_stmt(
463456
product_name=product_name,
464457
user_id=user_id,
465458
access_rights=AccessRightsClauses.can_read,
@@ -514,7 +507,7 @@ async def get_service_history_page(
514507
)
515508

516509
if filters:
517-
base_stmt = _apply_services_filters(base_stmt, filters)
510+
base_stmt = _services_sql.apply_services_filters(base_stmt, filters)
518511

519512
base_subquery = base_stmt.subquery()
520513

@@ -546,7 +539,7 @@ async def get_service_history_page(
546539
),
547540
)
548541
)
549-
.order_by(sql.desc(by_version(services_meta_data.c.version)))
542+
.order_by(sql.desc(_services_sql.by_version(services_meta_data.c.version)))
550543
.offset(offset)
551544
.limit(limit)
552545
)

0 commit comments

Comments
 (0)