aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-12-17 21:26:46 -0800
committerAlex Yatskov <alex@foosoft.net>2016-12-17 21:26:46 -0800
commit5be864bb6f1f911bec143566c768bf735a373743 (patch)
tree8f87276459e03e306c9f737f2d2278f77d917ad5 /ext/bg/js/database.js
parent5c755043fa2fb23f94f898fc57828277d7b02049 (diff)
WIP
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js25
1 files changed, 13 insertions, 12 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 980e9e40..6f474e77 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -64,14 +64,15 @@ class Database {
reading: row.reading,
tags: splitField(row.tags),
glossary: row.glossary,
+ dictionary: row.dictionary,
id: row.id
});
}
}).then(() => {
- return this.getTagMeta(dictionaries);
- }).then(tagMeta => {
+ return this.cacheTagMeta(dictionaries);
+ }).then(() => {
for (const result of results) {
- result.tagMeta = tagMeta;
+ result.tagMeta = this.tagMetaCache[result.dictionary] || {};
}
return results;
@@ -95,17 +96,17 @@ class Database {
});
}
}).then(() => {
- return this.getTagMeta(dictionaries);
- }).then(tagMeta => {
+ return this.cacheTagMeta(dictionaries);
+ }).then(() => {
for (const result of results) {
- result.tagMeta = tagMeta;
+ result.tagMeta = this.tagMetaCache[result.dictionary] || {};
}
return results;
});
}
- getTagMeta(dictionaries) {
+ cacheTagMeta(dictionaries) {
if (this.db === null) {
return Promise.reject('database not initialized');
}
@@ -119,7 +120,7 @@ class Database {
const tagMeta = this.tagMetaCache[dictionary] = {};
promises.push(
this.db.tagMeta.where('dictionary').equals(dictionary).each(row => {
- tagMeta[row.tag] = {
+ tagMeta[row.name] = {
category: row.category,
notes: row.notes,
order: row.order
@@ -128,7 +129,7 @@ class Database {
);
}
- return Promise.all(promises).then(() => this.tagMetaCache);
+ return Promise.all(promises);
}
getDictionaries() {
@@ -232,9 +233,9 @@ class Database {
const meta = tagMeta[tag];
rows.push({
name: tag,
- category: meta.category,
- notes: meta.notes,
- order: meta.order,
+ category: meta.category || 'default',
+ notes: meta.notes || '',
+ order: meta.order || Number.MAX_SAFE_INTEGER,
dictionary: title
});
}