cache viz worker at launch (#9589)

This commit is contained in:
qazal
2025-03-27 01:10:02 +08:00
committed by GitHub
parent d62ced8981
commit 8b717c345c
2 changed files with 7 additions and 4 deletions
+7 -2
View File
@@ -9,7 +9,12 @@ function intersectRect(r1, r2) {
}
const allWorkers = [];
window.renderGraph = function(graph, additions, name) {
let workerUrl = null;
window.renderGraph = async function(graph, additions, name) {
if (workerUrl == null) {
const resp = await Promise.all(["/assets/dagrejs.github.io/project/dagre/latest/dagre.min.js","/lib/worker.js"].map(u => fetch(u)));
workerUrl = URL.createObjectURL(new Blob([(await Promise.all(resp.map((r) => r.text()))).join("\n")], { type: "application/javascript" }));
}
while (allWorkers.length) {
const { worker, timeout } = allWorkers.pop();
worker.terminate();
@@ -22,7 +27,7 @@ window.renderGraph = function(graph, additions, name) {
d3.select("#bars").html("");
// ** start calculating the new layout (non-blocking)
worker = new Worker("/lib/worker.js");
worker = new Worker(workerUrl);
const progressMessage = document.querySelector(".progress-message");
const timeout = setTimeout(() => {
progressMessage.style.display = "block";
-2
View File
@@ -1,5 +1,3 @@
importScripts("../assets/dagrejs.github.io/project/dagre/latest/dagre.min.js");
const NODE_PADDING = 10;
const LINE_HEIGHT = 14;
const canvas = new OffscreenCanvas(0, 0);