Skip to content

Commit 1bc205b

Browse files
committed
findAndRemove & findOne
1 parent 91cf159 commit 1bc205b

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/party/loki-cache.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = class LokiCache extends EventEmitter {
3939
'$meta.id': id
4040
}).remove()
4141

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

4444
debug(found)
4545
if(found){
@@ -71,7 +71,7 @@ module.exports = class LokiCache extends EventEmitter {
7171
}
7272

7373
findById(type, id){
74-
const cachedMsg = this.db.getCollection(type).findOne({ '$meta.id': id })
74+
const cachedMsg = this.db.getCollection(type).findOne({'$meta.id': {'$eq': id}})
7575

7676
if(cachedMsg){
7777
delete cachedMsg.$loki
@@ -103,18 +103,18 @@ module.exports = class LokiCache extends EventEmitter {
103103
const collection = this.db.getCollection(type)
104104

105105
// check for cached version of message
106-
const cachedMsg = collection.findOne({ '$meta.id': id })
106+
const cachedMsg = collection.findOne({'$meta.id': {'$eq': id}})
107107

108108
// if backend set error or removed flag invalidate cache
109109
if (error || removed) {
110110
debug('invalidating msg!')
111111

112112
if (cachedMsg) {
113113
try{
114-
//collection.remove(cachedMsg)
115-
collection.findAndRemove({
116-
'$meta.id': id,
117-
})
114+
collection.remove(cachedMsg)
115+
//collection.findAndRemove({
116+
// '$meta.id': id,
117+
//})
118118
}
119119
catch(err){
120120
debug('WARN', err)
@@ -131,9 +131,10 @@ module.exports = class LokiCache extends EventEmitter {
131131

132132
// check if msg is already in cache
133133
if (cachedMsg) {
134-
collection.findAndRemove({
135-
'$meta.id': id,
136-
})
134+
collection.remove(cachedMsg)
135+
//collection.findAndRemove({
136+
// '$meta.id': id,
137+
//})
137138
}
138139

139140
// clone msg on insert - cache should follow backend
@@ -170,7 +171,7 @@ module.exports = class LokiCache extends EventEmitter {
170171
// get msg by id & strip loki metadata
171172
const cachedMsg = Object.assign(
172173
{},
173-
collection.findOne({ '$meta.id': id})
174+
collection.findOne({'$meta.id': {'$eq': id}})
174175
)
175176
delete cachedMsg.$loki
176177
delete cachedMsg.meta

0 commit comments

Comments
 (0)