aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 329399e8..12a2577f 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -166,23 +166,30 @@ class Database {
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) {
if (!this.db) {
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];
- if (!result) {
- await this.db.tagMeta.where('name').equals(name).each(row => {
- if (title === row.dictionary) {
- result = row;
- }
- });
+ let result = null;
+ await this.db.tagMeta.where('name').equals(name).each(row => {
+ if (title === row.dictionary) {
+ result = row;
+ }
+ });
- this.tagCache[title][name] = result;
- }
+ cache[name] = result;
return result;
}