Use Map for Translator.tagCache
This commit is contained in:
parent
e3c871bc00
commit
0e6b75438a
@ -27,7 +27,7 @@ class Translator {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.database = null;
|
this.database = null;
|
||||||
this.deinflector = null;
|
this.deinflector = null;
|
||||||
this.tagCache = {};
|
this.tagCache = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
async prepare() {
|
async prepare() {
|
||||||
@ -44,12 +44,12 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async purgeDatabase() {
|
async purgeDatabase() {
|
||||||
this.tagCache = {};
|
this.tagCache.clear();
|
||||||
await this.database.purge();
|
await this.database.purge();
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteDictionary(dictionaryName) {
|
async deleteDictionary(dictionaryName) {
|
||||||
this.tagCache = {};
|
this.tagCache.clear();
|
||||||
await this.database.deleteDictionary(dictionaryName);
|
await this.database.deleteDictionary(dictionaryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,22 +537,22 @@ class Translator {
|
|||||||
|
|
||||||
async getTagMetaList(names, title) {
|
async getTagMetaList(names, title) {
|
||||||
const tagMetaList = [];
|
const tagMetaList = [];
|
||||||
const cache = (
|
let cache = this.tagCache.get(title);
|
||||||
hasOwn(this.tagCache, title) ?
|
if (typeof cache === 'undefined') {
|
||||||
this.tagCache[title] :
|
cache = new Map();
|
||||||
(this.tagCache[title] = {})
|
this.tagCache.set(title, cache);
|
||||||
);
|
}
|
||||||
|
|
||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
const base = Translator.getNameBase(name);
|
const base = Translator.getNameBase(name);
|
||||||
|
|
||||||
if (hasOwn(cache, base)) {
|
let tagMeta = cache.get(base);
|
||||||
tagMetaList.push(cache[base]);
|
if (typeof tagMeta === 'undefined') {
|
||||||
} else {
|
tagMeta = await this.database.findTagForTitle(base, title);
|
||||||
const tagMeta = await this.database.findTagForTitle(base, title);
|
cache.set(base, tagMeta);
|
||||||
cache[base] = tagMeta;
|
|
||||||
tagMetaList.push(tagMeta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tagMetaList.push(tagMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tagMetaList;
|
return tagMetaList;
|
||||||
|
Loading…
Reference in New Issue
Block a user