Skip to content

Commit

Permalink
perf: ⚡ Simpler getAllGsInDir
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Aug 15, 2021
1 parent 3250462 commit 9197442
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/Components/TrailGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import type BreadcrumbsPlugin from "src/main";
import {
closeImpliedLinks,
getAllXGs,
mergeGs,
normalise,
openOrSwitch,
padArray,
Expand Down
5 changes: 2 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import type {
Directions,
dvFrontmatterCache,
HierarchyGraphs,
MergedGraphs,
} from "src/interfaces";
import MatrixView from "src/MatrixView";
import {
closeImpliedLinks,
debug,
getAllXGs,
getAllGsInDir,
getDVMetadataCache,
getNeighbourObjArr,
getObsMetadataCache,
Expand Down Expand Up @@ -336,7 +335,7 @@ export default class BreadcrumbsPlugin extends Plugin {
});

DIRECTIONS.forEach((dir) => {
const allXGs = getAllXGs(userHierarchies, graphs.hierGs, dir);
const allXGs = getAllGsInDir(userHierarchies, graphs.hierGs, dir);
const dirMerged = mergeGs(...Object.values(allXGs));
graphs.mergedGs[dir] = dirMerged;
});
Expand Down
41 changes: 24 additions & 17 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,27 +497,34 @@ export function removeUnlinkedNodes(g: Graph) {
return copy;
}

export function getAllXGs(
export function getAllGsInDir(
userHierarchies: userHierarchy[],
currGraphs: HierarchyGraphs[],
dir: Directions
) {
const fieldNamesInXDir = userHierarchies
.map((hier) => hier[dir])
.filter((field) => field.join() !== "")
.flat();

const allXGs: { [rel: string]: Graph } = {};

currGraphs.forEach((hierarchyGs) => {
fieldNamesInXDir.forEach((field) => {
const graph = hierarchyGs[dir][field];
if (graph) {
allXGs[field] = graph;
}
});
});
return allXGs;
const target = {};
const allGsInDir: { [field: string]: Graph } = Object.assign(
target,
...currGraphs.map((hierGs) => hierGs[dir])
);

// const fieldNamesInXDir = userHierarchies
// .map((hier) => hier[dir])
// .filter((field) => field.join() !== "")
// .flat();

// const allXGs: { [rel: string]: Graph } = {};

// currGraphs.forEach((hierarchyGs) => {
// fieldNamesInXDir.forEach((field) => {
// const graph = hierarchyGs[dir][field];
// if (graph) {
// allXGs[field] = graph;
// }
// });
// });
// console.log({ allXGs, allGsInDir });
return allGsInDir;
}

export function hierToStr(hier: userHierarchy) {
Expand Down

0 comments on commit 9197442

Please sign in to comment.