Added comment and improved KeyRange

vectorCLock can be used in following ways:
1. at X (at position)
2. from X ( lower bound)
3. from X to Y (upper and lower bound
4. to Y (upperBound)
This commit is contained in:
sairajzero 2019-10-20 01:27:08 +05:30
parent 0519fec34e
commit b9bb8de3f4

View File

@ -5354,19 +5354,19 @@
request = request.split(" ");
requestor = request[0];
request = JSON.parse(request[1]);
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.senderIDs || request.senderIDs.includes(v.senderID))) }, request.vectorClock, request.lastOnly)
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
.catch(error => console.log(error))
else
compactIDB.searchData(floGlobals.defaultStorage, (k, v) => { return (v.application == request.application && (!request.receiverID || v.receiverID == request.receiverID) && (!request.type || v.type == request.type) && (!request.senderIDs || request.senderIDs.includes(v.senderID))) }, request.vectorClock, request.lastOnly)
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
.catch(error => console.log(error))
var filterOptions = {
lowerKey: request.lowerVectorClock,
upperKey: request.upperVectorClock,
lastOnly: request.mostRecent,
atKey: request.atVectorClock,
patternEval: (k, v) => { return (v.application == request.application && (!request.receiverID || v.receiverID == request.receiverID) && (!request.comment || v.comment == request.comment) && (!request.type || v.type == request.type) && (!request.senderIDs || request.senderIDs.includes(v.senderID))) }
}
compactIDB.searchData( floGlobals.storageList.includes(request.application) ? request.application : floGlobals.defaultStorage, filterOptions)
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
.catch(error => console.log(error))
} catch (error) {
console.log(error.message)
}
});
//Event fired during incoming data
@ -5384,7 +5384,6 @@
var table = data.application;
else
var table = floGlobals.defaultStorage;
compactIDB.addData(table, {
senderID: data.senderID,
receiverID: data.receiverID,
@ -5395,7 +5394,6 @@
type: data.type,
comment: data.comment
})
}
})
} catch (error) {
@ -5536,18 +5534,24 @@
});
},
searchData: function (obsName, patternEval, startKey = 0, lastOnly = false, dbName = this.dbName) {
searchData: function (obsName, options = {}, dbName = this.dbName) {
options.lowerKey = options.atKey | options.lowerKey | 1
options.upperKey = options.atKey | options.upperKey | false
options.patternEval = options.patternEval | ((k,v) => {return true})
options.lastOnly = options.lastOnly | false
return new Promise((resolve, reject) => {
this.openDB(dbName).then(db => {
var obs = db.transaction(obsName, "readonly").objectStore(obsName);
var filteredResult = {}
let curReq = obs.openCursor(IDBKeyRange.lowerBound(startKey,true), lastOnly ? "prev":"next" );
let curReq = obs.openCursor(
options.upperKey ? IDBKeyRange.bound(options.lowerKey,options.upperKey) : IDBKeyRange.lowerBound(options.lowerKey),
options.lastOnly ? "prev":"next" );
curReq.onsuccess = (evt) => {
var cursor = evt.target.result;
if (cursor) {
if (patternEval(cursor.primaryKey, cursor.value)){
if (options.patternEval(cursor.primaryKey, cursor.value)){
filteredResult[cursor.primaryKey] = cursor.value;
lastOnly ? resolve(filteredResult) : cursor.continue();
options.lastOnly ? resolve(filteredResult) : cursor.continue();
}else
cursor.continue();
} else