fix(striker-ui-api): build OS list once on server load

main
Tsu-ba-me 3 years ago
parent ad864c3a21
commit e50d181a0d
  1. 26
      striker-ui-api/src/lib/consts/OS_LIST.ts
  2. 13
      striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts

@ -0,0 +1,26 @@
import { execSync } from 'child_process';
import SERVER_PATHS from './SERVER_PATHS';
type OSKeyMapToName = Record<string, string>;
const osList: string[] = execSync(
`${SERVER_PATHS.usr.sbin['striker-parse-os-list'].self} | ${SERVER_PATHS.usr.bin['sed'].self} -E 's/^.*name="os_list_([^"]+).*CDATA[[]([^]]+).*$/\\1,\\2/'`,
{
encoding: 'utf-8',
timeout: 10000,
},
).split('\n');
osList.pop();
const osKeyMapToName: OSKeyMapToName = osList.reduce((map, csv) => {
const [osKey, osName] = csv.split(',', 2);
map[osKey] = osName;
return map;
}, {} as OSKeyMapToName);
export const OS_LIST: Readonly<string[]> = osList;
export const OS_LIST_MAP: Readonly<OSKeyMapToName> = osKeyMapToName;

@ -1,7 +1,5 @@
import { execSync } from 'child_process';
import NODE_AND_DR_RESERVED_MEMORY_SIZE from '../../consts/NODE_AND_DR_RESERVED_MEMORY_SIZE'; import NODE_AND_DR_RESERVED_MEMORY_SIZE from '../../consts/NODE_AND_DR_RESERVED_MEMORY_SIZE';
import SERVER_PATHS from '../../consts/SERVER_PATHS'; import { OS_LIST } from '../../consts/OS_LIST';
import join from '../../join'; import join from '../../join';
import { sanitizeSQLParam } from '../../sanitizeSQLParam'; import { sanitizeSQLParam } from '../../sanitizeSQLParam';
@ -309,16 +307,9 @@ const buildQueryAnvilDetail = ({
[], [],
); );
const osList = execSync(
`${SERVER_PATHS.usr.sbin['striker-parse-os-list'].self} | ${SERVER_PATHS.usr.bin['sed'].self} -E 's/^.*name="os_list_([^"]+).*CDATA[[]([^]]+).*$/\\1,\\2/'`,
{ encoding: 'utf-8', timeout: 10000 },
).split('\n');
osList.pop();
results = { results = {
anvils, anvils,
osList, osList: OS_LIST,
}; };
} }

Loading…
Cancel
Save