Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 256 - Improve getting hosts performance #257

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/pages/Hosts/Hosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const Hosts = () => {
// Derived states - what we get from API
const hostDataResponse = useGettingHostQuery({
searchValue: "",
sizeLimit: 0,
sizelimit: 0,
apiVersion: apiVersion || API_VERSION_BACKUP,
} as HostsPayload);

Expand Down Expand Up @@ -162,12 +162,10 @@ const Hosts = () => {
hostDataResponse.data &&
batchResponse !== undefined
) {
const hostsListResult = batchResponse.result.results;
const hostsListSize = batchResponse.result.count;
const hostsListSize = batchResponse.length;
const hostsList: Host[] = [];

for (let i = 0; i < hostsListSize; i++) {
hostsList.push(hostsListResult[i].result);
hostsList.push(batchResponse[i]);
}

// Update 'Hosts' slice data
Expand Down
72 changes: 12 additions & 60 deletions src/services/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
PwPolicy,
KrbPolicy,
CertProfile,
Host,
} from "src/utils/datatypes/globalDataTypes";
import { apiToUser } from "src/utils/userUtils";
import { apiToPwPolicy } from "src/utils/pwPolicyUtils";
Expand Down Expand Up @@ -129,7 +130,7 @@ export interface UsersPayload {

export interface HostsPayload {
searchValue: string;
sizeLimit: number;
sizelimit: number;
apiVersion: string;
}

Expand Down Expand Up @@ -588,70 +589,21 @@ export const api = createApi({
providesTags: ["ActiveUsers"],
}),
// Hosts
gettingHost: build.query<BatchRPCResponse, HostsPayload>({
async queryFn(payloadData, _queryApi, _extraOptions, fetchWithBQ) {
const { searchValue, sizeLimit, apiVersion } = payloadData;

if (apiVersion === undefined) {
return {
error: {
status: "CUSTOM_ERROR",
data: "",
error: "API version not available",
} as FetchBaseQueryError,
};
}

gettingHost: build.query<Host[], HostsPayload>({
query: (payload) => {
// Prepare search parameters
const params = {
pkey_only: true,
sizelimit: sizeLimit,
version: apiVersion,
version: payload.apiVersion,
sizelimit: payload.sizelimit,
all: true,
};

// Prepare payload
const payloadDataIds: Command = {
return getCommand({
method: "host_find",
params: [[searchValue], params],
};

// Make call using 'fetchWithBQ'
const getGroupIDsResult = await fetchWithBQ(getCommand(payloadDataIds));
// Return possible errors
if (getGroupIDsResult.error) {
return { error: getGroupIDsResult.error as FetchBaseQueryError };
}
// If no error: cast and assign 'uids'
const hostIdResponseData = getGroupIDsResult.data as FindRPCResponse;

const fqdns: string[] = [];
const itemsCount = hostIdResponseData.result.result.length as number;
for (let i = 0; i < itemsCount; i++) {
const hostId = hostIdResponseData.result.result[i] as fqdnType;
const { fqdn } = hostId;
fqdns.push(fqdn[0] as string);
}

// 2ND CALL - GET PARTIAL HOSTS INFO
// Prepare payload
const payloadHostDataBatch: Command[] = fqdns.map((fqdn) => ({
method: "host_show",
params: [[fqdn], {}],
}));

// Make call using 'fetchWithBQ'
const partialHostsInfoResult = await fetchWithBQ(
getBatchCommand(payloadHostDataBatch as Command[], apiVersion)
);

// Return results
return partialHostsInfoResult.data
? { data: partialHostsInfoResult.data as BatchRPCResponse }
: {
error:
partialHostsInfoResult.error as unknown as FetchBaseQueryError,
};
params: [[payload.searchValue], params],
});
},
transformResponse: (response: FindRPCResponse): Host[] =>
response.result.result as unknown as Host[],
}),
// Autommeber Users
autoMemberRebuildUsers: build.mutation<FindRPCResponse, any[]>({
Expand Down
Loading