@kedem/okdb 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/okdb.js +1 -1
- package/okdb-processor-worker.js +1 -1
- package/okdb.js +1 -1
- package/package.json +1 -1
package/okdb-processor-worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const{parentPort:parentPort,workerData:workerData}=require("worker_threads"),lmdb=require("lmdb"),mode=workerData.mode??"snapshot";async function runSnapshotMode(){const{envPath:e,type:t,batchSize:r,mapSize:o}=workerData,
|
|
1
|
+
"use strict";const{parentPort:parentPort,workerData:workerData}=require("worker_threads"),lmdb=require("lmdb"),mode=workerData.mode??"snapshot";async function runSnapshotMode(){const{envPath:e,type:t,batchSize:r,mapSize:o,compression:s}=workerData,a=lmdb.open(e,{readOnly:!0,maxDbs:128,mapSize:o??268435456,compression:s??!0}),n=a.openDB(`type:${t}:data`,{dupSort:!1,useVersions:!0}).getRange({snapshot:!0});let p=null;const i=()=>new Promise(e=>{p=e});parentPort.on("message",e=>{if("ack"===e.type&&p){const e=p;p=null,e()}});let c=[],l=0;for(const{key:e,value:t,version:o}of n)if(c.push({key:e,value:t,version:o}),c.length>=r){const e=c.length;parentPort.postMessage({type:"batch",entries:c,processed:l}),await i(),l+=e,c=[]}c.length>0&&(parentPort.postMessage({type:"batch",entries:c,processed:l}),await i(),l+=c.length),await a.close(),parentPort.postMessage({type:"done",total:l})}async function runLiveMode(){const{handlerModule:e,envPath:t,mapSize:r,compression:o}=workerData,s=require(e.module),a=s[e.export]??s.default??s;if("function"!=typeof a)throw new Error(`live worker: ${e.export} is not a function in ${e.module}`);await new Promise(e=>{parentPort.on("message",t=>{"flush"===t.type?Promise.resolve().then(()=>a(t.changes,{mode:"live"})).then(()=>{parentPort.postMessage({type:"flush-done",lastClock:t.lastClock})}).catch(e=>{parentPort.postMessage({type:"error",error:e.message??String(e)})}):"stop"===t.type&&e()})}),process.exit(0)}"live"===mode?runLiveMode().catch(e=>{parentPort.postMessage({type:"error",error:e.message??String(e)}),process.exit(1)}):runSnapshotMode().catch(e=>{parentPort.postMessage({type:"error",error:e.message??String(e)}),process.exit(1)});
|