(feat) proxy add pagination on /user/info endpoint

This commit is contained in:
ishaan-jaff 2024-02-29 12:30:47 -08:00
parent 7d26eaf481
commit 432ce90a9a
2 changed files with 16 additions and 2 deletions

View file

@ -4311,6 +4311,14 @@ async def user_info(
default=False, default=False,
description="set to true to View all users. When using view_all, don't pass user_id", description="set to true to View all users. When using view_all, don't pass user_id",
), ),
page: int = fastapi.Query(
default=1,
description="Page number for pagination. Only use when view_all is true",
),
page_size: int = fastapi.Query(
default=10,
description="Number of items per page. Only use when view_all is true",
),
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
): ):
""" """
@ -4332,8 +4340,10 @@ async def user_info(
if user_id is not None: if user_id is not None:
user_info = await prisma_client.get_data(user_id=user_id) user_info = await prisma_client.get_data(user_id=user_id)
elif view_all == True: elif view_all == True:
offset = (page - 1) * page_size # default is 0
limit = page_size # default is 10
user_info = await prisma_client.get_data( user_info = await prisma_client.get_data(
table_name="user", query_type="find_all" table_name="user", query_type="find_all", offset=offset, limit=limit
) )
return user_info return user_info
else: else:

View file

@ -613,6 +613,10 @@ class PrismaClient:
query_type: Literal["find_unique", "find_all"] = "find_unique", query_type: Literal["find_unique", "find_all"] = "find_unique",
expires: Optional[datetime] = None, expires: Optional[datetime] = None,
reset_at: Optional[datetime] = None, reset_at: Optional[datetime] = None,
offset: Optional[int] = None, # pagination, what row number to start from
limit: Optional[
int
] = None, # pagination, number of rows to getch when find_all==True
): ):
try: try:
response: Any = None response: Any = None
@ -748,7 +752,7 @@ class PrismaClient:
) )
else: else:
response = await self.db.litellm_usertable.find_many( # type: ignore response = await self.db.litellm_usertable.find_many( # type: ignore
order={"spend": "desc"}, order={"spend": "desc"}, take=limit, skip=offset
) )
return response return response
elif table_name == "spend": elif table_name == "spend":