Skip to content

Commit 6e106df

Browse files
committed
Add limit to shop search
1 parent 33c4051 commit 6e106df

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

app/core/search.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ async def search_script(
489489
async def search_shop(
490490
conn: AsyncConnection,
491491
search_param: ShopSearchQueryParams,
492-
limit: int = 100,
493492
) -> list[MstShop]:
494493
if not search_param.hasSearchParams():
495494
raise HTTPException(status_code=400, detail=INSUFFICIENT_QUERY)
@@ -511,14 +510,12 @@ async def search_shop(
511510
shop_type_ints=shop_type_ints,
512511
pay_type_ints=pay_type_ints,
513512
purchase_type_ints=purchase_type_ints,
513+
limit=search_param.limit,
514514
)
515515

516516
if search_param.name:
517517
matches = [item for item in matches if match_name(search_param.name, item.name)]
518518

519-
if len(matches) > limit: # pragma: no cover
520-
raise HTTPException(status_code=403, detail=TOO_MANY_RESULTS.format(limit))
521-
522519
return sorted(matches, key=lambda shop: shop.id)
523520

524521

app/db/helpers/event.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async def get_shop_search(
7272
shop_type_ints: Iterable[int] | None = None,
7373
pay_type_ints: Iterable[int] | None = None,
7474
purchase_type_ints: Iterable[int] | None = None,
75+
limit: int = 100,
7576
) -> list[MstShop]:
7677
from_clause: Join | Table = mstShop
7778
where_clause: list[_ColumnExpressionArgument[bool]] = [true()]
@@ -86,7 +87,11 @@ async def get_shop_search(
8687
where_clause.append(mstShop.c.purchaseType.in_(purchase_type_ints))
8788

8889
shop_search_stmt = (
89-
select(mstShop).distinct().select_from(from_clause).where(and_(*where_clause))
90+
select(mstShop)
91+
.distinct()
92+
.select_from(from_clause)
93+
.where(and_(*where_clause))
94+
.limit(limit)
9095
)
9196

9297
return [

app/routers/nice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ async def find_shop(
951951
lang: Language = Depends(language_parameter),
952952
) -> Response:
953953
async with get_db(search_param.region) as conn:
954-
matches = await search.search_shop(conn, search_param, limit=10000)
954+
matches = await search.search_shop(conn, search_param)
955955
return list_response(
956956
await get_nice_shops_from_raw(conn, search_param.region, matches, lang)
957957
)

app/routers/raw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ async def find_shop(
808808
search_param: ShopSearchQueryParams = Depends(ShopSearchQueryParams),
809809
) -> Response:
810810
async with get_db(search_param.region) as conn:
811-
matches = await search.search_shop(conn, search_param, limit=10000)
811+
matches = await search.search_shop(conn, search_param)
812812
return list_response(await raw.get_shop_entities(conn, matches))
813813

814814

app/schemas/search.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ class ShopSearchQueryParams:
524524
type: list[NiceShopType] = Query([])
525525
payType: list[NicePayType] = Query([])
526526
purchaseType: list[NicePurchaseType] = Query([])
527+
limit: int = Query(10000, le=10000)
527528

528529
def hasSearchParams(self) -> bool:
529530
return any(

0 commit comments

Comments
 (0)