Skip to content

Commit

Permalink
Fixed the relationship table data
Browse files Browse the repository at this point in the history
  • Loading branch information
Hunter19823 committed Apr 30, 2024
1 parent 9641e32 commit fa81d77
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
self.onmessage = function (e) {
optimizeDataSearch().then(r => {
postMessage({data: DATA, cache: LOOK_UP_CACHE});
postMessage({data: DATA, cache: LOOK_UP_CACHE, RELATIONSHIP_GRAPH: getRelationshipGraphAsJSON(RELATIONSHIP_GRAPH)});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ function createOptimizationWorkerThread() {
}

function onWindowLoad() {
console.log("Window Loaded.");
console.log("Window Loaded. Now optimizing data.");
setToast("Please wait while data is being indexed. This should only take a few seconds.");
const WORKER = createOptimizationWorkerThread();
WORKER.onmessage = (e) => {
Expand All @@ -458,6 +458,9 @@ function onWindowLoad() {
Object.entries(NEW_CACHE).forEach(([key, value]) => {
LOOK_UP_CACHE.set(key, value);
});
const NEW_RELATIONSHIP_GRAPH = e.data.RELATIONSHIP_GRAPH;
console.log("New Relationship Graph: ", NEW_RELATIONSHIP_GRAPH);
loadJSONToRelationshipGraph(NEW_RELATIONSHIP_GRAPH);
WORKER.terminate();
clearToast();
onHashChange();
Expand All @@ -484,7 +487,6 @@ function onWindowLoad() {
setToast("An error occurred while optimizing data. Please refresh the page to try again. Please report this issue if it persists.");
}
WORKER.postMessage({task: TASKS.OPTIMIZE})
console.log("This shouldn't have to wait for data to be indexed.");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,28 @@ function getAllRelations(id) {
})
});
return relations;
}

function getRelationshipGraphAsJSON(map) {
const output = {};
map.entries().forEach(([relationshipType, relationshipMap]) => {
const relationshipOutput = {};
relationshipMap.entries().forEach(([from, toSet]) => {
relationshipOutput[from] = Array.from(toSet);
});
output[relationshipType] = relationshipOutput;
});
return JSON.stringify(output);
}

function loadJSONToRelationshipGraph(json) {
RELATIONSHIP_GRAPH.clear();
const parsed = JSON.parse(json);
Object.entries(parsed).forEach(([relationshipType, relationMap]) => {
const relationshipOutput = new Map();
Object.entries(relationMap).forEach(([from, toSet]) => {
relationshipOutput.set(parseInt(from), new Set(toSet));
});
RELATIONSHIP_GRAPH.set(relationshipType, relationshipOutput);
});
}

0 comments on commit fa81d77

Please sign in to comment.