Comparing version 3.0.1 to 3.0.2
{ | ||
"name": "jembadb", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Json Embeddable Appendable Database", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -690,10 +690,11 @@ 'use strict'; | ||
_parseQueryShards(query) { | ||
let selectedShards = []; | ||
let selectedShards = new Set; | ||
if (!query.shards) { | ||
selectedShards = Array.from(this.shardList.keys()); | ||
selectedShards = this.shardList.keys(); | ||
} else { | ||
if (Array.isArray(query.shards)) { | ||
for (const shard of query.shards) { | ||
if (this.shardList.has(shard)) | ||
selectedShards.push(shard); | ||
if (!selectedShards.has(shard) && this.shardList.has(shard)) { | ||
selectedShards.add(shard); | ||
} | ||
} | ||
@@ -704,3 +705,3 @@ } else if (typeof(query.shards) === 'string') { | ||
if (shardTestFunc(shard)) | ||
selectedShards.push(shard); | ||
selectedShards.add(shard); | ||
} | ||
@@ -711,3 +712,4 @@ } else { | ||
} | ||
//opened shards first | ||
//opened shards first, to array | ||
selectedShards = this._getOpenedShardsFirst(selectedShards); | ||
@@ -714,0 +716,0 @@ return selectedShards; |
@@ -45,13 +45,16 @@ 'use strict'; | ||
async getRow(id) { | ||
let block = this.blockList.get(this.blockIndex.get(id)); | ||
const block = this.blockList.get(this.blockIndex.get(id)); | ||
if (block) { | ||
if (!block.rows) { | ||
await this.loadBlock(block); | ||
} | ||
if (!block) { | ||
return; | ||
} | ||
this.unloadBlocksIfNeeded();//no await | ||
if (block.rows) { | ||
return block.rows.get(id); | ||
} else { | ||
await this.loadBlock(block); | ||
const result = block.rows.get(id); | ||
this.unloadBlocksIfNeeded(); | ||
return result; | ||
} | ||
return; | ||
} | ||
@@ -167,40 +170,23 @@ | ||
async unloadBlocksIfNeeded() { | ||
this.needUnload = true; | ||
if (this.unloadingBlocks) | ||
unloadBlocksIfNeeded() { | ||
if (this.loadedBlocks.length <= this.loadedBlocksCount) | ||
return; | ||
this.unloadingBlocks = true; | ||
try { | ||
while (this.needUnload) { | ||
this.needUnload = false; | ||
if (this.destroyed) | ||
return; | ||
//check loaded | ||
let missed = new Set(); | ||
while (this.loadedBlocks.length > this.loadedBlocksCount) { | ||
const index = this.loadedBlocks.shift(); | ||
if (index >= this.lastSavedBlockIndex) { | ||
missed.add(index); | ||
continue; | ||
} | ||
const block = this.blockList.get(index); | ||
await utils.sleep(10); | ||
//check loaded | ||
let missed = new Map(); | ||
while (this.loadedBlocks.length >= this.loadedBlocksCount) { | ||
const index = this.loadedBlocks.shift(); | ||
if (index >= this.lastSavedBlockIndex) { | ||
missed.set(index, 1); | ||
continue; | ||
} | ||
const block = this.blockList.get(index); | ||
if (block) { | ||
block.rows = null; | ||
if (block) { | ||
block.rows = null; | ||
//console.log(`unloaded block ${block.index}`); | ||
} | ||
if (this.destroyed) | ||
return; | ||
} | ||
this.loadedBlocks = this.loadedBlocks.concat(Array.from(missed.keys())); | ||
} | ||
} finally { | ||
this.unloadingBlocks = false; | ||
} | ||
this.loadedBlocks = this.loadedBlocks.concat(Array.from(missed)); | ||
} | ||
@@ -499,3 +485,3 @@ | ||
await this.finalizeBlocks(); | ||
this.unloadBlocksIfNeeded();//no await | ||
this.unloadBlocksIfNeeded(); | ||
@@ -502,0 +488,0 @@ //dumps if needed |
180948
4759