Skip to content

Commit 81e4346

Browse files
committed
Drop original limit decorator as now replaced by proper pagination
1 parent 5224502 commit 81e4346

1 file changed

Lines changed: 0 additions & 30 deletions

File tree

api/server/utils/decorator.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
from functools import wraps
2-
from fastapi import Request
3-
from typing import Callable, Any, Union
4-
5-
6-
def limited(default_limit: int = 100):
7-
def decorator(func: Callable):
8-
@wraps(func)
9-
async def wrapper(*args, **kwargs) -> Any:
10-
# Extract request from kwargs (FastAPI automatically passes it)
11-
request: Request = kwargs.get("request")
12-
limit: Union[str, int] = request.query_params.get("limit", default_limit)
13-
14-
try:
15-
limit = int(limit) # Ensure limit is an integer
16-
except ValueError:
17-
limit = default_limit # Fallback if conversion fails
18-
19-
# Call the original function
20-
result = await func(*args, **kwargs)
21-
22-
# Apply limit if the result is a list
23-
if isinstance(result, list):
24-
return result[:limit]
25-
return result # If not a list, return as-is
26-
27-
return wrapper
28-
29-
return decorator
30-
311
from functools import wraps
322
from fastapi import Request
333
from typing import Callable, Any, Union, Tuple

0 commit comments

Comments
 (0)