MCPcopy
hub / github.com/opentrace/opentrace / MainThreadLbugEngine

Class MainThreadLbugEngine

ui/src/store/lbugEngine.ts:67–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67class MainThreadLbugEngine implements LbugEngine {
68 private db: Database | null = null;
69 private conn: Connection | null = null;
70 private closed = false;
71
72 async init(): Promise<void> {
73 lbug.setWorkerPath('/lbug_wasm_worker.js');
74 await lbug.init();
75 // Buffer pool size note: lbug accepts a `bufferPoolSize` argument here,
76 // but in WASM the linear memory is a single shared heap — reserving more
77 // for the page cache leaves less for everything else (CSV temp files,
78 // query state, parser tables). An explicit 512 MB reservation broke ingest
79 // even for small repos, so we let the engine's auto-sizing decide. To
80 // genuinely fit larger graphs the right move is to reduce extraction depth
81 // or use server mode rather than push this number up.
82 this.db = new lbug.Database(':memory:');
83 await this.db.init();
84 this.conn = new lbug.Connection(this.db);
85 await this.conn.init();
86 this.closed = false;
87 }
88
89 async query(cypher: string): Promise<Record<string, unknown>[]> {
90 if (!this.conn) throw new Error('LbugEngine.query before init()');
91 const result = await this.conn.query(cypher);
92 try {
93 return await result.getAllObjects();
94 } finally {
95 await result.close();
96 }
97 }
98
99 async exec(cypher: string): Promise<void> {
100 if (!this.conn) throw new Error('LbugEngine.exec before init()');
101 const result = await this.conn.query(cypher);
102 await result.close();
103 }
104
105 async fsWrite(path: string, data: Uint8Array): Promise<void> {
106 await lbug.FS.writeFile(path, data);
107 }
108
109 async fsUnlink(path: string): Promise<void> {
110 await lbug.FS.unlink(path);
111 }
112
113 async close(): Promise<void> {
114 if (this.closed) return;
115 this.closed = true;
116 try {
117 await this.conn?.close();
118 } catch {
119 /* ignore */
120 }
121 try {
122 await this.db?.close();
123 } catch {
124 /* ignore */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected