Improved searchData from IDB
IDB search data will only search in a lowerBound keyRange (thus reduces searching) new IDB search option : can send only the last data matching the pattern added type to be searched in request (optional) made receiverID as optional in request data filtering
This commit is contained in:
parent
d44432f698
commit
99f5958336
22
index.html
22
index.html
@ -5352,13 +5352,15 @@
|
|||||||
console.log('Request :', request);
|
console.log('Request :', request);
|
||||||
try {
|
try {
|
||||||
request = request.split(" ");
|
request = request.split(" ");
|
||||||
if (floGlobals.storageList.includes(request[1]))
|
requestor = request[0];
|
||||||
compactIDB.searchData(request[1], (k, v) => { return (k > request[3] && v.application == request[1] && v.receiverID == request[2]) })
|
request = JSON.parse(request[1]);
|
||||||
.then(result => floSupernode.supernodeClientWS.send(`${request[0]} ${JSON.stringify(result)}`))
|
if (floGlobals.storageList.includes(request.application))
|
||||||
|
compactIDB.searchData(request.application, (k, v) => { return (v.application == request.application && (!request.receiverID || v.receiverID == request.receiverID) && (!request.type || v.type == request.type)) }, request.vectorClock, request.lastOnly)
|
||||||
|
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
|
||||||
.catch(error => console.log(error))
|
.catch(error => console.log(error))
|
||||||
else
|
else
|
||||||
compactIDB.searchData(floGlobals.defaultStorage, (k, v) => { return (k > request[3] && v.application == request[1] && v.receiverID == request[2]) })
|
compactIDB.searchData(floGlobals.defaultStorage, (k, v) => { return (v.application == request.application && (!request.receiverID || v.receiverID == request.receiverID) && (!request.type || v.type == request.type)) }, request.vectorClock, request.lastOnly)
|
||||||
.then(result => floSupernode.supernodeClientWS.send(`${request[0]} ${JSON.stringify(result)}`))
|
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
|
||||||
.catch(error => console.log(error))
|
.catch(error => console.log(error))
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -5534,18 +5536,20 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
searchData: function (obsName, patternEval, dbName = this.dbName) {
|
searchData: function (obsName, patternEval, startKey = 0, lastOnly = false, dbName = this.dbName) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.openDB(dbName).then(db => {
|
this.openDB(dbName).then(db => {
|
||||||
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
|
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
|
||||||
var filteredResult = {}
|
var filteredResult = {}
|
||||||
let curReq = obs.openCursor();
|
let curReq = obs.openCursor(IDBKeyRange.lowerBound(startKey,true), lastOnly ? "prev":"next" );
|
||||||
curReq.onsuccess = (evt) => {
|
curReq.onsuccess = (evt) => {
|
||||||
var cursor = evt.target.result;
|
var cursor = evt.target.result;
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
if (patternEval(cursor.primaryKey, cursor.value))
|
if (patternEval(cursor.primaryKey, cursor.value)){
|
||||||
filteredResult[cursor.primaryKey] = cursor.value;
|
filteredResult[cursor.primaryKey] = cursor.value;
|
||||||
cursor.continue();
|
lastOnly ? resolve(filteredResult) : cursor.continue();
|
||||||
|
}else
|
||||||
|
cursor.continue();
|
||||||
} else
|
} else
|
||||||
resolve(filteredResult);
|
resolve(filteredResult);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user