Merge branch 'fix-CPU-blocking' into pre-release
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
const { parentPort, workerData } = require('worker_threads');
|
||||
const Database = require('better-sqlite3');
|
||||
|
||||
if (!parentPort) throw new Error("Must be run in a worker thread");
|
||||
|
||||
try {
|
||||
const { filePath } = workerData;
|
||||
const db = new Database(filePath, { readonly: true, fileMustExist: true });
|
||||
|
||||
// This is the CPU-heavy operation
|
||||
const result = db.prepare("PRAGMA integrity_check;").get();
|
||||
|
||||
db.close();
|
||||
parentPort.postMessage(result.integrity_check === "ok");
|
||||
} catch (error) {
|
||||
// Any error means invalid or corrupt DB
|
||||
parentPort.postMessage(false);
|
||||
}
|
||||
Reference in New Issue
Block a user