fix: hash all indexed keys

This commit is contained in:
thecodrr
2020-11-09 10:30:33 +05:00
parent 142ec35bfe
commit 4a5daf2a8d
5 changed files with 22 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
import Storage from "./storage";
import Indexer from "./indexer";
import SparkMD5 from "spark-md5";
export default class PersistentCachedMap {
/**
@@ -19,6 +20,7 @@ export default class PersistentCachedMap {
}
async set(key, value) {
key = SparkMD5.hash(key);
this.map.set(key, value);
await this.indexer.write(key, value);
await this.indexer.index(key);
@@ -31,10 +33,12 @@ export default class PersistentCachedMap {
}
get(key) {
key = SparkMD5.hash(key);
return this.map.get(key);
}
has(key) {
key = SparkMD5.hash(key);
return this.map.has(key);
}