Skip to content

Commit 8b6ac8a

Browse files
committed
chore: added limit to the search api calls
1 parent 9c14bde commit 8b6ac8a

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-backend/src/routes/costManagementAccess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export const getCostManagementAccess: (
8484

8585
// Fetch clusters and projects in parallel for better performance
8686
const [clustersResponse, projectsResponse] = await Promise.all([
87-
costManagementApi.searchOpenShiftClusters('', { token }),
88-
costManagementApi.searchOpenShiftProjects('', { token }),
87+
costManagementApi.searchOpenShiftClusters('', { token, limit: 1000 }),
88+
costManagementApi.searchOpenShiftProjects('', { token, limit: 1000 }),
8989
]);
9090

9191
const clustersData = await clustersResponse.json();

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-common/src/clients/cost-management/CostManagementSlimApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export interface CostManagementSlimApi {
3131
): Promise<void>;
3232
searchOpenShiftProjects(
3333
search?: string,
34-
options?: { token?: string },
34+
options?: { token?: string; limit?: number },
3535
): Promise<
3636
TypedResponse<{ data: Array<{ value: string }>; meta?: any; links?: any }>
3737
>;
3838
searchOpenShiftClusters(
3939
search?: string,
40-
options?: { token?: string },
40+
options?: { token?: string; limit?: number },
4141
): Promise<
4242
TypedResponse<{
4343
data: Array<{ value: string; cluster_alias: string }>;

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-common/src/clients/cost-management/CostManagementSlimClient.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,29 @@ export class CostManagementSlimClient implements CostManagementSlimApi {
434434
/**
435435
* Search OpenShift projects
436436
* @param search - Search term to filter projects
437+
* @param options - Optional request options including token and limit
438+
* @param options.token - Bearer token for authentication (backend use)
439+
* @param options.limit - Maximum number of results to return (default: 10, use large number for all)
437440
*/
438441
public async searchOpenShiftProjects(
439442
search: string = '',
440-
options?: { token?: string },
443+
options?: { token?: string; limit?: number },
441444
): Promise<
442445
TypedResponse<{ data: Array<{ value: string }>; meta?: any; links?: any }>
443446
> {
444447
const baseUrl = await this.discoveryApi.getBaseUrl('proxy');
445-
const searchParam = search ? `?search=${encodeURIComponent(search)}` : '';
446-
const url = `${baseUrl}/cost-management/v1/resource-types/openshift-projects/${searchParam}`;
448+
449+
// Build query parameters
450+
const params = new URLSearchParams();
451+
if (search) {
452+
params.append('search', search);
453+
}
454+
if (options?.limit !== undefined) {
455+
params.append('limit', String(options.limit));
456+
}
457+
const queryString = params.toString();
458+
const queryPart = queryString ? `?${queryString}` : '';
459+
const url = `${baseUrl}/cost-management/v1/resource-types/openshift-projects/${queryPart}`;
447460

448461
// If token provided externally (backend use), use it directly
449462
if (options?.token) {
@@ -480,7 +493,7 @@ export class CostManagementSlimClient implements CostManagementSlimApi {
480493
*/
481494
public async searchOpenShiftClusters(
482495
search: string = '',
483-
options?: { token?: string },
496+
options?: { token?: string; limit?: number },
484497
): Promise<
485498
TypedResponse<{
486499
data: Array<{ value: string; cluster_alias: string }>;
@@ -489,8 +502,18 @@ export class CostManagementSlimClient implements CostManagementSlimApi {
489502
}>
490503
> {
491504
const baseUrl = await this.discoveryApi.getBaseUrl('proxy');
492-
const searchParam = search ? `?search=${encodeURIComponent(search)}` : '';
493-
const url = `${baseUrl}/cost-management/v1/resource-types/openshift-clusters/${searchParam}`;
505+
506+
// Build query parameters
507+
const params = new URLSearchParams();
508+
if (search) {
509+
params.append('search', search);
510+
}
511+
if (options?.limit !== undefined) {
512+
params.append('limit', String(options.limit));
513+
}
514+
const queryString = params.toString();
515+
const queryPart = queryString ? `?${queryString}` : '';
516+
const url = `${baseUrl}/cost-management/v1/resource-types/openshift-clusters/${queryPart}`;
494517

495518
// If token provided externally (backend use), use it directly
496519
if (options?.token) {

0 commit comments

Comments
 (0)