Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit ed50fab

Browse files
Use more efficient lookup by index
1 parent e4b93c2 commit ed50fab

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/cache/cache_ram.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ class CacheRAM extends CacheBase {
9797

9898
_reserveBlock(key, size) {
9999
// Free any existing block for this key
100-
this._index.findAndUpdate({'fileId' : key}, doc => doc['fileId'] = undefined);
100+
let doc = this._index.by('fileId', key);
101+
if(doc) {
102+
doc.fileId = undefined;
103+
this._index.update(doc);
104+
}
101105

102106
// Find the best free block to use
103107
let freeBlock;
@@ -187,7 +191,10 @@ class CacheRAM extends CacheBase {
187191
helpers.log(consts.LOG_INFO, `Writing ${pagePath}`);
188192

189193
await fs.writeFile(pagePath, this._pages[page.index]);
190-
this._pageMeta.findAndUpdate({'index': page.index}, doc => doc.dirty = false);
194+
195+
let doc = this._pageMeta.by('index', page.index);
196+
doc.dirty = false;
197+
this._pageMeta.update(doc);
191198
});
192199

193200
return Promise.all(promises);

0 commit comments

Comments
 (0)