Skip to content

Commit 032656e

Browse files
committed
fix: orval query param generation
1 parent f2e7f3f commit 032656e

4 files changed

Lines changed: 30 additions & 22 deletions

File tree

app/node/__init__.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@
1414
}
1515

1616

17-
def calculate_max_message_size(active_users_count: int) -> int:
18-
"""
19-
max_message_size to 64MB.
20-
21-
Args:
22-
active_users_count: Number of active users in the system
23-
24-
Returns:
25-
int: Max message size in bytes (64MB)
26-
"""
27-
return 64 * 1024 * 1024 # 64MB
28-
29-
3017
class NodeManager:
3118
def __init__(self):
3219
self._nodes: dict[int, PasarGuardNode] = {}
@@ -136,4 +123,4 @@ async def update_user(self, user: ProtoUser) -> None:
136123
node_manager: NodeManager = NodeManager()
137124

138125

139-
__all__ = ["calculate_max_message_size", "core_users", "node_manager"]
126+
__all__ = ["core_users", "node_manager"]

app/operation/node.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
validate_user_count_metric_scope,
6060
)
6161
from app.nats.node_rpc import node_nats_client
62-
from app.node import calculate_max_message_size, core_users, node_manager
62+
from app.node import core_users, node_manager
6363
from app.operation import BaseOperation, OperatorType
6464
from app.utils.logger import get_logger
6565
from config import runtime_settings
@@ -191,7 +191,9 @@ async def _update_single_node_status(
191191
asyncio.create_task(notification.error_node(node_notif))
192192

193193
@staticmethod
194-
async def _get_core_users_map(db: AsyncSession, core_ids: set[int]) -> tuple[dict[int, object | None], dict[int, list]]:
194+
async def _get_core_users_map(
195+
db: AsyncSession, core_ids: set[int]
196+
) -> tuple[dict[int, object | None], dict[int, list]]:
195197
if not core_ids:
196198
return {}, {}
197199

@@ -629,12 +631,9 @@ async def _connect_single_node_local(self, db: AsyncSession, node_id: int) -> No
629631
core = cores_by_id.get(core_id)
630632
users = users_by_core.get(core_id, [])
631633

632-
# Calculate max_message_size based on this node's payload size
633-
max_message_size = calculate_max_message_size(len(users))
634-
635634
# Update node manager
636635
try:
637-
await node_manager.update_node(db_node, max_message_size=max_message_size)
636+
await node_manager.update_node(db_node)
638637
except NodeAPIError as e:
639638
# Update status to error using simple CRUD
640639
await update_node_status(

dashboard/src/service/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3486,7 +3486,7 @@ export const useRemoveAdminById = <TData = Awaited<ReturnType<typeof removeAdmin
34863486
* @summary Get Admins
34873487
*/
34883488
export const getAdmins = (adminSortOption: BodyType<AdminSortOption[]>, params?: GetAdminsParams, signal?: AbortSignal) => {
3489-
return orvalFetcher<AdminsResponse>({ url: `/api/admins`, method: 'GET', headers: { 'Content-Type': 'application/json' }, params, signal })
3489+
return orvalFetcher<AdminsResponse>({ url: `/api/admins`, method: 'GET', headers: { 'Content-Type': 'application/json' }, data: adminSortOption, params, signal })
34903490
}
34913491

34923492
export const getGetAdminsQueryKey = (adminSortOption: AdminSortOption[], params?: GetAdminsParams) => {
@@ -10033,7 +10033,7 @@ export function useGetUserSubUpdateListById<TData = Awaited<ReturnType<typeof ge
1003310033
* @summary Get Users
1003410034
*/
1003510035
export const getUsers = (getUsersBody: BodyType<GetUsersBody>, params?: GetUsersParams, signal?: AbortSignal) => {
10036-
return orvalFetcher<UsersResponse>({ url: `/api/users`, method: 'GET', headers: { 'Content-Type': 'application/json' }, params, signal })
10036+
return orvalFetcher<UsersResponse>({ url: `/api/users`, method: 'GET', headers: { 'Content-Type': 'application/json' }, data: getUsersBody, params, signal })
1003710037
}
1003810038

1003910039
export const getGetUsersQueryKey = (getUsersBody: GetUsersBody, params?: GetUsersParams) => {

dashboard/src/service/http.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ type OvalFetcherParams = FetchOptions<'json'> & {
3939
data?: FetchOptions<'json'>['body']
4040
}
4141
export const orvalFetcher = async <T>({ url, method, params, data: body }: OvalFetcherParams): Promise<T> => {
42+
if (method === 'GET') {
43+
// 1. If we have data in a GET request, it means arguments were shifted or
44+
// we manually passed data to rescue dropped parameters.
45+
if (body && typeof body === 'object' && !Array.isArray(body)) {
46+
params = { ...params, ...(body as Record<string, unknown>) }
47+
body = undefined
48+
} else if (body) {
49+
// If it's not an object (e.g. just a string or array), we can't easily merge it
50+
// unless we know the key. But for the known cases (status), it's usually an object
51+
// when passed from the frontend filters.
52+
}
53+
54+
// 2. If 'query' is present in params, check if it looks like React Query options.
55+
if (params && 'query' in params) {
56+
const queryVal = (params as any).query
57+
if (queryVal && typeof queryVal === 'object' && ('staleTime' in queryVal || 'gcTime' in queryVal || 'retry' in queryVal)) {
58+
const { query: _query, ...rest } = params as any
59+
params = rest
60+
}
61+
}
62+
}
63+
4264
return fetcher(url, {
4365
method,
4466
params,

0 commit comments

Comments
 (0)