From 4d4b819d6c197df6e0f91ba170d0ee909dfcb5c9 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 13 Sep 2017 17:26:02 -0700 Subject: tag caching --- ext/bg/js/database.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'ext/bg/js/database.js') 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; } -- cgit v1.2.3