Skip to content

Commit 11b6662

Browse files
committed
improve loki querying
1 parent d29c4be commit 11b6662

6 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/bouncer/db/loki-db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ module.exports = class LokiDb extends IDb {
314314

315315
debug('its good, updating', dbDoc)
316316

317-
let old = collection.findOne( {'$meta.id': dbDoc._id})
317+
let old = collection.findOne( {'$meta.id': {'$eq': dbDoc._id}})
318318

319319
let mergedDoc = {...old, ...dbDoc}
320320

src/bouncer/mongo-query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const buildQueryDoc = (node, cursor) => {
176176
// -> { 'param.path': value }
177177
case 'equals':
178178
cursor.push({
179-
[node.param.join('.')]: node.value
179+
[node.param.join('.')]: {'$eq': node.value}
180180
})
181181
return
182182

src/party/local/loki-party.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class LokiParty extends IParty {
3131
constructor ({path, dbAdapter, qbOptions, lokiOptions, ...options}) {
3232
super(options)
3333

34+
this.dbStarted = false
35+
3436
this.db = new LokiDb({
3537
dbAdapter,
3638
path, factory: this.factory,
@@ -54,7 +56,11 @@ class LokiParty extends IParty {
5456
*/
5557
async start(){
5658
await super.start()
57-
await this.db.start()
59+
60+
if(!this.dbStarted){
61+
await this.db.start()
62+
this.dbStarted = true
63+
}
5864
}
5965

6066
static get Loki(){

src/party/local/tingo-party.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class TingoParty extends IParty {
2424
constructor ({path, qbOptions, tingoOptions, ...options}) {
2525
super(options)
2626

27+
this.dbStarted = false
2728
this.db = new TingoDb({
2829
path, factory: this.factory,
2930
tingoOptions
@@ -45,7 +46,10 @@ class TingoParty extends IParty {
4546
*/
4647
async start(){
4748
await super.start()
48-
await this.db.start()
49+
if(!this.dbStarted){
50+
await this.db.start()
51+
this.dbStarted = true
52+
}
4953
}
5054

5155

src/party/local/zango-party.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ZangoParty extends IParty {
2727
constructor ({dbname, qbOptions, ...options}) {
2828
super(options)
2929

30+
this.dbStarted = false
3031
this.db = new ZangoDb({
3132
dbname, factory: this.factory,
3233
})
@@ -48,7 +49,10 @@ class ZangoParty extends IParty {
4849
*/
4950
async start(){
5051
await super.start()
51-
await this.db.start()
52+
if(!this.dbStarted){
53+
await this.db.start()
54+
this.dbStarted = true
55+
}
5256
}
5357

5458

src/party/loki-cache.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = class LokiCache extends EventEmitter {
4141

4242
var found = collection.findOne({'$meta.id': {'$eq': id}})
4343

44-
debug(found)
44+
debug('removing found', found)
4545
if(found){
4646

4747
try{
@@ -52,7 +52,7 @@ module.exports = class LokiCache extends EventEmitter {
5252
collection.findAndRemove({'$meta.id': id})
5353
}
5454

55-
debug('remove found', found)
55+
debug('removed found', found)
5656

5757
this._emitChange(found, 'remove')
5858
}
@@ -105,6 +105,8 @@ module.exports = class LokiCache extends EventEmitter {
105105
// check for cached version of message
106106
const cachedMsg = collection.findOne({'$meta.id': {'$eq': id}})
107107

108+
debug('cachedMsg', cachedMsg)
109+
108110
// if backend set error or removed flag invalidate cache
109111
if (error || removed) {
110112
debug('invalidating msg!')

0 commit comments

Comments
 (0)