Use non-async function for cache lookups
This commit is contained in:
parent
a4f8a459de
commit
664a318d7f
@ -166,23 +166,30 @@ class Database {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findTagForTitleCached(name, title) {
|
||||||
|
if (this.tagCache.hasOwnProperty(title)) {
|
||||||
|
const cache = this.tagCache[title];
|
||||||
|
if (cache.hasOwnProperty(name)) {
|
||||||
|
return cache[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async findTagForTitle(name, title) {
|
async findTagForTitle(name, title) {
|
||||||
if (!this.db) {
|
if (!this.db) {
|
||||||
throw 'Database not initialized';
|
throw 'Database not initialized';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tagCache[title] = this.tagCache[title] || {};
|
const cache = (this.tagCache.hasOwnProperty(title) ? this.tagCache[title] : (this.tagCache[title] = {}));
|
||||||
|
|
||||||
let result = this.tagCache[title][name];
|
let result = null;
|
||||||
if (!result) {
|
await this.db.tagMeta.where('name').equals(name).each(row => {
|
||||||
await this.db.tagMeta.where('name').equals(name).each(row => {
|
if (title === row.dictionary) {
|
||||||
if (title === row.dictionary) {
|
result = row;
|
||||||
result = row;
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.tagCache[title][name] = result;
|
cache[name] = result;
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -298,15 +298,13 @@ class Translator {
|
|||||||
const tags = [];
|
const tags = [];
|
||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
const base = Translator.getNameBase(name);
|
const base = Translator.getNameBase(name);
|
||||||
const meta = await this.database.findTagForTitle(base, title);
|
let meta = this.database.findTagForTitleCached(base, title);
|
||||||
|
if (typeof meta === 'undefined') {
|
||||||
const tag = {name};
|
meta = await this.database.findTagForTitle(base, title);
|
||||||
for (const prop in meta || {}) {
|
|
||||||
if (prop !== 'name') {
|
|
||||||
tag[prop] = meta[prop];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tag = Object.assign({}, meta !== null ? meta : {}, {name});
|
||||||
|
|
||||||
tags.push(dictTagSanitize(tag));
|
tags.push(dictTagSanitize(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,16 +315,18 @@ class Translator {
|
|||||||
const stats = {};
|
const stats = {};
|
||||||
for (const name in items) {
|
for (const name in items) {
|
||||||
const base = Translator.getNameBase(name);
|
const base = Translator.getNameBase(name);
|
||||||
const meta = await this.database.findTagForTitle(base, title);
|
let meta = this.database.findTagForTitleCached(base, title);
|
||||||
const group = stats[meta.category] = stats[meta.category] || [];
|
if (typeof meta === 'undefined') {
|
||||||
|
meta = await this.database.findTagForTitle(base, title);
|
||||||
const stat = {name, value: items[name]};
|
if (meta === null) {
|
||||||
for (const prop in meta || {}) {
|
continue;
|
||||||
if (prop !== 'name') {
|
|
||||||
stat[prop] = meta[prop];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const group = stats[meta.category] = stats[meta.category] || [];
|
||||||
|
|
||||||
|
const stat = Object.assign({}, meta, {name, value: items[name]});
|
||||||
|
|
||||||
group.push(dictTagSanitize(stat));
|
group.push(dictTagSanitize(stat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user