summaryrefslogtreecommitdiff
path: root/ext/bg/js/database.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-09-13 17:26:02 -0700
committerAlex Yatskov <alex@foosoft.net>2017-09-13 17:26:02 -0700
commit4d4b819d6c197df6e0f91ba170d0ee909dfcb5c9 (patch)
treecb6446be836483d1f961ead28c06c932de444261 /ext/bg/js/database.js
parent13961e6a10554fdc43c5b1b66f28ea72d2fc21b6 (diff)
tag caching
Diffstat (limited to 'ext/bg/js/database.js')
-rw-r--r--ext/bg/js/database.js22
1 files changed, 15 insertions, 7 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 6ae36db2..1b171b03 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -20,6 +20,7 @@
class Database {
constructor() {
this.db = null;
+ this.tagCache = {};
}
async prepare() {
@@ -51,6 +52,7 @@ class Database {
this.db.close();
await this.db.delete();
this.db = null;
+ this.tagCache = {};
await this.prepare();
}
@@ -131,17 +133,23 @@ class Database {
return results;
}
- async findTag(name, titles) {
+ async findTag(name, title) {
if (!this.db) {
throw 'database not initialized';
}
- let result = null;
- await this.db.tagMeta.where('name').equals(name).each(row => {
- if (titles.includes(row.dictionary)) {
- result = row;
- }
- });
+ 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;
+ }
+ });
+
+ this.tagCache[title][name] = result;
+ }
return result;
}