Improve resource scan

Walk only unique paths
This commit is contained in:
2020-05-04 11:04:29 +03:00
parent d350603c48
commit 789c5aba3e
20 changed files with 113 additions and 58 deletions

34
src/Helpers/Path.ts Normal file
View File

@ -0,0 +1,34 @@
export interface PathQuery {
[key: string]: string | number | undefined;
}
export interface PathDefinition {
name: string;
query: PathQuery;
}
export type PathList = Array<PathDefinition>;
export function path(base: string, query: PathQuery = {}): string {
let parts: string[] = [];
for (let name of Object.keys(query)) {
if (query[name] !== undefined) {
parts.push(`${name}=${query[name]}`);
}
}
return base + (parts.length ? '?' + parts.join('&') : '');
}
export function uniqPaths(paths: PathList): PathList {
const keys: { [k: string]: boolean | undefined } = {};
const result: PathList = [];
for (let path of paths) {
const pathKey = JSON.stringify(path);
if (keys[pathKey]) {
continue;
}
keys[pathKey] = true;
result.push(path);
}
return result;
}