tangled
alpha
login
or
join now
olaren.dev
/
pdsls
forked from
pds.ls/pdsls
0
fork
atom
atmosphere explorer
0
fork
atom
overview
issues
pulls
pipelines
use worker to validate logs
handle.invalid
1 month ago
72e12a98
2c8c3e13
verified
This commit was signed with the committer's
known signature
.
handle.invalid
SSH Key Fingerprint:
SHA256:mBrT4x0JdzLpbVR95g1hjI1aaErfC02kmLRkPXwsYCk=
+24
-14
2 changed files
expand all
collapse all
unified
split
src
views
logs.tsx
workers
plc-validate.ts
+13
-14
src/views/logs.tsx
···
3
3
defs,
4
4
IndexedEntry,
5
5
IndexedEntryLog,
6
6
-
processIndexedEntryLog,
7
6
} from "@atcute/did-plc";
8
8
-
import { createEffect, createResource, createSignal, For, Show } from "solid-js";
7
7
+
import { createEffect, createResource, createSignal, For, onCleanup, Show } from "solid-js";
9
8
import { localDateFromTimestamp } from "../utils/date.js";
10
9
import { createOperationHistory, DiffEntry, groupBy } from "../utils/plc-logs.js";
10
10
+
import PlcValidateWorker from "../workers/plc-validate.ts?worker";
11
11
import { plcDirectory } from "./settings.jsx";
12
12
13
13
type PlcEvent = "handle" | "rotation_key" | "service" | "verification_method";
···
32
32
return Array.from(groupBy(opHistory, (item) => item.orig));
33
33
};
34
34
35
35
-
const validateLog = async (logs: IndexedEntryLog) => {
36
36
-
try {
37
37
-
await processIndexedEntryLog(props.did as any, logs);
38
38
-
setValidLog(true);
39
39
-
} catch (e) {
40
40
-
console.error(e);
41
41
-
setValidLog(false);
42
42
-
}
43
43
-
};
44
44
-
45
35
const [plcOps] =
46
36
createResource<[IndexedEntry<CompatibleOperationOrTombstone>, DiffEntry[]][]>(fetchPlcLogs);
47
37
38
38
+
let worker: Worker | undefined;
39
39
+
onCleanup(() => worker?.terminate());
40
40
+
48
41
createEffect(() => {
49
42
const logs = rawLogs();
50
43
if (logs) {
51
44
setValidLog(undefined);
52
52
-
// Defer validation to next tick to avoid blocking rendering
53
53
-
setTimeout(() => validateLog(logs), 0);
45
45
+
worker?.terminate();
46
46
+
worker = new PlcValidateWorker();
47
47
+
worker.onmessage = (e: MessageEvent<{ valid: boolean }>) => {
48
48
+
setValidLog(e.data.valid);
49
49
+
worker?.terminate();
50
50
+
worker = undefined;
51
51
+
};
52
52
+
worker.postMessage({ did: props.did, logs });
54
53
}
55
54
});
56
55
+11
src/workers/plc-validate.ts
···
1
1
+
import { processIndexedEntryLog } from "@atcute/did-plc";
2
2
+
3
3
+
self.onmessage = async (e: MessageEvent<{ did: string; logs: any }>) => {
4
4
+
const { did, logs } = e.data;
5
5
+
try {
6
6
+
await processIndexedEntryLog(did as any, logs);
7
7
+
self.postMessage({ valid: true });
8
8
+
} catch {
9
9
+
self.postMessage({ valid: false });
10
10
+
}
11
11
+
};