summaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-13 16:42:04 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-13 16:42:04 -0700
commit13961e6a10554fdc43c5b1b66f28ea72d2fc21b6 (patch)
tree1ceb76cf56964188f8d59fecd564a4a1f2b95296 /ext/bg/js/database.js
parentba8451f429d1055f91f79473f32204efb2c041db (diff)
better tag handling
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js32
1 files changed, 9 insertions, 23 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index cd53f681..6ae36db2 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -20,7 +20,6 @@
class Database {
constructor() {
this.db = null;
- this.tagCache = {};
}
async prepare() {
@@ -38,7 +37,7 @@ class Database {
this.db.version(3).stores({
termFreq: '++,dictionary,expression',
kanjiFreq: '++,dictionary,character',
- tagMeta: '++,dictionary'
+ tagMeta: '++,dictionary,name'
});
await this.db.open();
@@ -52,7 +51,6 @@ class Database {
this.db.close();
await this.db.delete();
this.db = null;
- this.tagCache = {};
await this.prepare();
}
@@ -78,11 +76,6 @@ class Database {
}
});
- await this.cacheTagMeta(titles);
- for (const result of results) {
- result.tagMeta = this.tagCache[result.dictionary] || {};
- }
-
return results;
}
@@ -120,11 +113,6 @@ class Database {
}
});
- await this.cacheTagMeta(titles);
- for (const result of results) {
- result.tagMeta = this.tagCache[result.dictionary] || {};
- }
-
return results;
}
@@ -143,21 +131,19 @@ class Database {
return results;
}
- async cacheTagMeta(titles) {
+ async findTag(name, titles) {
if (!this.db) {
throw 'database not initialized';
}
- for (const title of titles) {
- if (!this.tagCache[title]) {
- const tagMeta = {};
- await this.db.tagMeta.where('dictionary').equals(title).each(row => {
- tagMeta[row.name] = {category: row.category, notes: row.notes, order: row.order};
- });
-
- this.tagCache[title] = tagMeta;
+ let result = null;
+ await this.db.tagMeta.where('name').equals(name).each(row => {
+ if (titles.includes(row.dictionary)) {
+ result = row;
}
- }
+ });
+
+ return result;
}
async getDictionaries() {