From 9b68089b6b994becd673f4e421bb7dc99976be2c Mon Sep 17 00:00:00 2001 From: Aaron Chong Date: Fri, 8 Mar 2024 15:13:20 +0800 Subject: [PATCH] Query requests in chunks as well Signed-off-by: Aaron Chong --- packages/api-client/lib/openapi/api.ts | 166 +++++++++++++++++- packages/api-client/lib/version.ts | 2 +- packages/api-client/schema/index.ts | 124 +++++++++++++ .../dashboard/src/components/app-base.tsx | 1 - .../src/components/tasks/tasks-app.tsx | 51 ++++-- 5 files changed, 321 insertions(+), 23 deletions(-) diff --git a/packages/api-client/lib/openapi/api.ts b/packages/api-client/lib/openapi/api.ts index 73e295a2c..4fc8099ab 100644 --- a/packages/api-client/lib/openapi/api.ts +++ b/packages/api-client/lib/openapi/api.ts @@ -8898,10 +8898,30 @@ export const TasksApiAxiosParamCreator = function (configuration?: Configuration /** * * @summary Task States Count + * @param {string} [taskId] comma separated list of task ids + * @param {string} [category] comma separated list of task categories + * @param {string} [requester] comma separated list of requester names + * @param {string} [pickup] comma separated list of pickup names + * @param {string} [destination] comma separated list of destination names + * @param {string} [assignedTo] comma separated list of assigned robot names + * @param {string} [status] comma separated list of statuses + * @param {string} [requestTimeBetween] The period of request time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. + * @param {string} [startTimeBetween] The period of starting time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. + * @param {string} [finishTimeBetween] The period of finishing time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. \"-60000\" - Fetches logs in the last minute. * @param {*} [options] Override http request option. * @throws {RequiredError} */ taskStatesCountTasksCountGet: async ( + taskId?: string, + category?: string, + requester?: string, + pickup?: string, + destination?: string, + assignedTo?: string, + status?: string, + requestTimeBetween?: string, + startTimeBetween?: string, + finishTimeBetween?: string, options: AxiosRequestConfig = {}, ): Promise => { const localVarPath = `/tasks/count`; @@ -8916,6 +8936,46 @@ export const TasksApiAxiosParamCreator = function (configuration?: Configuration const localVarHeaderParameter = {} as any; const localVarQueryParameter = {} as any; + if (taskId !== undefined) { + localVarQueryParameter['task_id'] = taskId; + } + + if (category !== undefined) { + localVarQueryParameter['category'] = category; + } + + if (requester !== undefined) { + localVarQueryParameter['requester'] = requester; + } + + if (pickup !== undefined) { + localVarQueryParameter['pickup'] = pickup; + } + + if (destination !== undefined) { + localVarQueryParameter['destination'] = destination; + } + + if (assignedTo !== undefined) { + localVarQueryParameter['assigned_to'] = assignedTo; + } + + if (status !== undefined) { + localVarQueryParameter['status'] = status; + } + + if (requestTimeBetween !== undefined) { + localVarQueryParameter['request_time_between'] = requestTimeBetween; + } + + if (startTimeBetween !== undefined) { + localVarQueryParameter['start_time_between'] = startTimeBetween; + } + + if (finishTimeBetween !== undefined) { + localVarQueryParameter['finish_time_between'] = finishTimeBetween; + } + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = { @@ -9496,13 +9556,43 @@ export const TasksApiFp = function (configuration?: Configuration) { /** * * @summary Task States Count + * @param {string} [taskId] comma separated list of task ids + * @param {string} [category] comma separated list of task categories + * @param {string} [requester] comma separated list of requester names + * @param {string} [pickup] comma separated list of pickup names + * @param {string} [destination] comma separated list of destination names + * @param {string} [assignedTo] comma separated list of assigned robot names + * @param {string} [status] comma separated list of statuses + * @param {string} [requestTimeBetween] The period of request time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. + * @param {string} [startTimeBetween] The period of starting time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. + * @param {string} [finishTimeBetween] The period of finishing time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. \"-60000\" - Fetches logs in the last minute. * @param {*} [options] Override http request option. * @throws {RequiredError} */ async taskStatesCountTasksCountGet( + taskId?: string, + category?: string, + requester?: string, + pickup?: string, + destination?: string, + assignedTo?: string, + status?: string, + requestTimeBetween?: string, + startTimeBetween?: string, + finishTimeBetween?: string, options?: AxiosRequestConfig, ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.taskStatesCountTasksCountGet( + taskId, + category, + requester, + pickup, + destination, + assignedTo, + status, + requestTimeBetween, + startTimeBetween, + finishTimeBetween, options, ); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); @@ -9958,12 +10048,46 @@ export const TasksApiFactory = function ( /** * * @summary Task States Count + * @param {string} [taskId] comma separated list of task ids + * @param {string} [category] comma separated list of task categories + * @param {string} [requester] comma separated list of requester names + * @param {string} [pickup] comma separated list of pickup names + * @param {string} [destination] comma separated list of destination names + * @param {string} [assignedTo] comma separated list of assigned robot names + * @param {string} [status] comma separated list of statuses + * @param {string} [requestTimeBetween] The period of request time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. + * @param {string} [startTimeBetween] The period of starting time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. + * @param {string} [finishTimeBetween] The period of finishing time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. \"-60000\" - Fetches logs in the last minute. * @param {*} [options] Override http request option. * @throws {RequiredError} */ - taskStatesCountTasksCountGet(options?: any): AxiosPromise { + taskStatesCountTasksCountGet( + taskId?: string, + category?: string, + requester?: string, + pickup?: string, + destination?: string, + assignedTo?: string, + status?: string, + requestTimeBetween?: string, + startTimeBetween?: string, + finishTimeBetween?: string, + options?: any, + ): AxiosPromise { return localVarFp - .taskStatesCountTasksCountGet(options) + .taskStatesCountTasksCountGet( + taskId, + category, + requester, + pickup, + destination, + assignedTo, + status, + requestTimeBetween, + startTimeBetween, + finishTimeBetween, + options, + ) .then((request) => request(axios, basePath)); }, /** @@ -10443,13 +10567,47 @@ export class TasksApi extends BaseAPI { /** * * @summary Task States Count + * @param {string} [taskId] comma separated list of task ids + * @param {string} [category] comma separated list of task categories + * @param {string} [requester] comma separated list of requester names + * @param {string} [pickup] comma separated list of pickup names + * @param {string} [destination] comma separated list of destination names + * @param {string} [assignedTo] comma separated list of assigned robot names + * @param {string} [status] comma separated list of statuses + * @param {string} [requestTimeBetween] The period of request time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. + * @param {string} [startTimeBetween] The period of starting time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. + * @param {string} [finishTimeBetween] The period of finishing time to fetch, in unix millis. This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive. Example: \"1000,2000\" - Fetches logs between unix millis 1000 and 2000. \"-60000\" - Fetches logs in the last minute. * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TasksApi */ - public taskStatesCountTasksCountGet(options?: AxiosRequestConfig) { + public taskStatesCountTasksCountGet( + taskId?: string, + category?: string, + requester?: string, + pickup?: string, + destination?: string, + assignedTo?: string, + status?: string, + requestTimeBetween?: string, + startTimeBetween?: string, + finishTimeBetween?: string, + options?: AxiosRequestConfig, + ) { return TasksApiFp(this.configuration) - .taskStatesCountTasksCountGet(options) + .taskStatesCountTasksCountGet( + taskId, + category, + requester, + pickup, + destination, + assignedTo, + status, + requestTimeBetween, + startTimeBetween, + finishTimeBetween, + options, + ) .then((request) => request(this.axios, this.basePath)); } diff --git a/packages/api-client/lib/version.ts b/packages/api-client/lib/version.ts index 604d6d8a8..0fbf7ed81 100644 --- a/packages/api-client/lib/version.ts +++ b/packages/api-client/lib/version.ts @@ -3,6 +3,6 @@ import { version as rmfModelVer } from 'rmf-models'; export const version = { rmfModels: rmfModelVer, - rmfServer: 'f40b701e1843a78e9e57bb4d2de337c20e75fecd', + rmfServer: '1cc0fa25a937ab0736dd77757f48d964e3e19c8a', openapiGenerator: '6.2.1', }; diff --git a/packages/api-client/schema/index.ts b/packages/api-client/schema/index.ts index 35c3d84d7..2bff5da52 100644 --- a/packages/api-client/schema/index.ts +++ b/packages/api-client/schema/index.ts @@ -676,6 +676,124 @@ export default { tags: ['Tasks'], summary: 'Task States Count', operationId: 'task_states_count_tasks_count_get', + parameters: [ + { + description: 'comma separated list of task ids', + required: false, + schema: { + title: 'Task Id', + type: 'string', + description: 'comma separated list of task ids', + }, + name: 'task_id', + in: 'query', + }, + { + description: 'comma separated list of task categories', + required: false, + schema: { + title: 'Category', + type: 'string', + description: 'comma separated list of task categories', + }, + name: 'category', + in: 'query', + }, + { + description: 'comma separated list of requester names', + required: false, + schema: { + title: 'Requester', + type: 'string', + description: 'comma separated list of requester names', + }, + name: 'requester', + in: 'query', + }, + { + description: 'comma separated list of pickup names', + required: false, + schema: { + title: 'Pickup', + type: 'string', + description: 'comma separated list of pickup names', + }, + name: 'pickup', + in: 'query', + }, + { + description: 'comma separated list of destination names', + required: false, + schema: { + title: 'Destination', + type: 'string', + description: 'comma separated list of destination names', + }, + name: 'destination', + in: 'query', + }, + { + description: 'comma separated list of assigned robot names', + required: false, + schema: { + title: 'Assigned To', + type: 'string', + description: 'comma separated list of assigned robot names', + }, + name: 'assigned_to', + in: 'query', + }, + { + description: 'comma separated list of statuses', + required: false, + schema: { + title: 'Status', + type: 'string', + description: 'comma separated list of statuses', + }, + name: 'status', + in: 'query', + }, + { + description: + '\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ', + required: false, + schema: { + title: 'Request Time Between', + type: 'string', + description: + '\n The period of request time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ', + }, + name: 'request_time_between', + in: 'query', + }, + { + description: + '\n The period of starting time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ', + required: false, + schema: { + title: 'Start Time Between', + type: 'string', + description: + '\n The period of starting time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n ', + }, + name: 'start_time_between', + in: 'query', + }, + { + description: + '\n The period of finishing time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n "-60000" - Fetches logs in the last minute.\n ', + required: false, + schema: { + title: 'Finish Time Between', + type: 'string', + description: + '\n The period of finishing time to fetch, in unix millis.\n\n This must be a comma separated string, \'X,Y\' to fetch between X millis and Y millis inclusive.\n\n Example:\n "1000,2000" - Fetches logs between unix millis 1000 and 2000.\n "-60000" - Fetches logs in the last minute.\n ', + }, + name: 'finish_time_between', + in: 'query', + }, + ], responses: { '200': { description: 'Successful Response', @@ -685,6 +803,12 @@ export default { }, }, }, + '422': { + description: 'Validation Error', + content: { + 'application/json': { schema: { $ref: '#/components/schemas/HTTPValidationError' } }, + }, + }, }, }, }, diff --git a/packages/dashboard/src/components/app-base.tsx b/packages/dashboard/src/components/app-base.tsx index b6ebd242f..0e76dc200 100644 --- a/packages/dashboard/src/components/app-base.tsx +++ b/packages/dashboard/src/components/app-base.tsx @@ -76,7 +76,6 @@ export function AppBase({ children }: React.PropsWithChildren<{}>): JSX.Element React.useEffect(() => { const sub = AppEvents.loadingBackdrop.subscribe((value) => { - console.log('got event'); setOpenLoadingBackdrop(value); }); return () => sub.unsubscribe(); diff --git a/packages/dashboard/src/components/tasks/tasks-app.tsx b/packages/dashboard/src/components/tasks/tasks-app.tsx index 7ac77e52f..c01080ee3 100644 --- a/packages/dashboard/src/components/tasks/tasks-app.tsx +++ b/packages/dashboard/src/components/tasks/tasks-app.tsx @@ -33,6 +33,7 @@ import { TaskSummary } from './task-summary'; import { downloadCsvFull, downloadCsvMinimal } from './utils'; const RefreshTaskQueueTableInterval = 15000; +const QueryLimit = 100; enum TaskTablePanel { QueueTable = 0, @@ -248,13 +249,24 @@ export const TasksApp = React.memo( return []; } - const taskStateCount = (await rmf.tasksApi.taskStatesCountTasksCountGet()).data; - console.log(taskStateCount); - const QUERY_LIMIT = 100; - const queriesRequired = Math.ceil(taskStateCount / QUERY_LIMIT); + const taskStateCount = ( + await rmf.tasksApi.taskStatesCountTasksCountGet( + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + `0,${timestamp.getTime()}`, + undefined, + undefined, + ) + ).data; + const queriesRequired = Math.ceil(taskStateCount / QueryLimit); const allTasks: TaskState[] = []; for (let i = 0; i < queriesRequired; i++) { - console.log(`Querying task state bunch of index ${i}`); const resp = await rmf.tasksApi.queryTaskStatesTasksGet( undefined, undefined, @@ -266,8 +278,8 @@ export const TasksApp = React.memo( `0,${timestamp.getTime()}`, undefined, undefined, - QUERY_LIMIT, - i * QUERY_LIMIT, + QueryLimit, + i * QueryLimit, '-unix_millis_start_time', undefined, ); @@ -281,18 +293,23 @@ export const TasksApp = React.memo( return {}; } - const taskIds: string[] = tasks.map((task) => task.booking.id); - const taskIdsQuery = taskIds.join(','); - const taskRequests = (await rmf.tasksApi.queryTaskRequestsTasksRequestsGet(taskIdsQuery)) - .data; - const taskRequestMap: Record = {}; - let requestIndex = 0; - for (const id of taskIds) { - if (requestIndex < taskRequests.length && taskRequests[requestIndex]) { - taskRequestMap[id] = taskRequests[requestIndex]; + const allTaskIds: string[] = tasks.map((task) => task.booking.id); + const queriesRequired = Math.ceil(allTaskIds.length / QueryLimit); + for (let i = 0; i < queriesRequired; i++) { + const endingIndex = Math.min(allTaskIds.length, (i + 1) * QueryLimit); + const taskIds = allTaskIds.slice(i * QueryLimit, endingIndex); + const taskIdsQuery = taskIds.join(','); + const taskRequests = (await rmf.tasksApi.queryTaskRequestsTasksRequestsGet(taskIdsQuery)) + .data; + + let requestIndex = 0; + for (const id of taskIds) { + if (requestIndex < taskRequests.length && taskRequests[requestIndex]) { + taskRequestMap[id] = taskRequests[requestIndex]; + } + ++requestIndex; } - ++requestIndex; } return taskRequestMap; };