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:
parent
0519fec34e
commit
b9bb8de3f4
36
index.html
36
index.html
@ -5354,19 +5354,19 @@
|
|||||||
request = request.split(" ");
|
request = request.split(" ");
|
||||||
requestor = request[0];
|
requestor = request[0];
|
||||||
request = JSON.parse(request[1]);
|
request = JSON.parse(request[1]);
|
||||||
if (floGlobals.storageList.includes(request.application))
|
var filterOptions = {
|
||||||
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)
|
lowerKey: request.lowerVectorClock,
|
||||||
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
|
upperKey: request.upperVectorClock,
|
||||||
.catch(error => console.log(error))
|
lastOnly: request.mostRecent,
|
||||||
else
|
atKey: request.atVectorClock,
|
||||||
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)
|
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))) }
|
||||||
.then(result => floSupernode.supernodeClientWS.send(`${requestor} ${JSON.stringify(result)}`))
|
}
|
||||||
.catch(error => console.log(error))
|
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) {
|
} catch (error) {
|
||||||
console.log(error.message)
|
console.log(error.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Event fired during incoming data
|
//Event fired during incoming data
|
||||||
@ -5384,7 +5384,6 @@
|
|||||||
var table = data.application;
|
var table = data.application;
|
||||||
else
|
else
|
||||||
var table = floGlobals.defaultStorage;
|
var table = floGlobals.defaultStorage;
|
||||||
|
|
||||||
compactIDB.addData(table, {
|
compactIDB.addData(table, {
|
||||||
senderID: data.senderID,
|
senderID: data.senderID,
|
||||||
receiverID: data.receiverID,
|
receiverID: data.receiverID,
|
||||||
@ -5395,7 +5394,6 @@
|
|||||||
type: data.type,
|
type: data.type,
|
||||||
comment: data.comment
|
comment: data.comment
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} 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) => {
|
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(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) => {
|
curReq.onsuccess = (evt) => {
|
||||||
var cursor = evt.target.result;
|
var cursor = evt.target.result;
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
if (patternEval(cursor.primaryKey, cursor.value)){
|
if (options.patternEval(cursor.primaryKey, cursor.value)){
|
||||||
filteredResult[cursor.primaryKey] = cursor.value;
|
filteredResult[cursor.primaryKey] = cursor.value;
|
||||||
lastOnly ? resolve(filteredResult) : cursor.continue();
|
options.lastOnly ? resolve(filteredResult) : cursor.continue();
|
||||||
}else
|
}else
|
||||||
cursor.continue();
|
cursor.continue();
|
||||||
} else
|
} else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user