Add additional database bulk methods
This commit is contained in:
parent
9364a7cb4e
commit
d212d0aba1
@ -58,7 +58,7 @@ class Database {
|
|||||||
await this.prepare();
|
await this.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
async findTermsBulk(terms, titles) {
|
async findTermsBulk(termList, titles) {
|
||||||
this.validate();
|
this.validate();
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
@ -77,8 +77,8 @@ class Database {
|
|||||||
const dbIndex1 = dbTerms.index('expression');
|
const dbIndex1 = dbTerms.index('expression');
|
||||||
const dbIndex2 = dbTerms.index('reading');
|
const dbIndex2 = dbTerms.index('reading');
|
||||||
|
|
||||||
for (let i = 0; i < terms.length; ++i) {
|
for (let i = 0; i < termList.length; ++i) {
|
||||||
const only = IDBKeyRange.only(terms[i]);
|
const only = IDBKeyRange.only(termList[i]);
|
||||||
promises.push(
|
promises.push(
|
||||||
Database.getAll(dbIndex1, only, i, processRow),
|
Database.getAll(dbIndex1, only, i, processRow),
|
||||||
Database.getAll(dbIndex2, only, i, processRow)
|
Database.getAll(dbIndex2, only, i, processRow)
|
||||||
@ -103,6 +103,32 @@ class Database {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findTermsExactBulk(termList, readingList, titles) {
|
||||||
|
this.validate();
|
||||||
|
|
||||||
|
const promises = [];
|
||||||
|
const results = [];
|
||||||
|
const processRow = (row, index) => {
|
||||||
|
if (row.reading === readingList[index] && titles.includes(row.dictionary)) {
|
||||||
|
results.push(Database.createTerm(row, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const db = this.db.backendDB();
|
||||||
|
const dbTransaction = db.transaction(['terms'], 'readonly');
|
||||||
|
const dbTerms = dbTransaction.objectStore('terms');
|
||||||
|
const dbIndex = dbTerms.index('expression');
|
||||||
|
|
||||||
|
for (let i = 0; i < termList.length; ++i) {
|
||||||
|
const only = IDBKeyRange.only(termList[i]);
|
||||||
|
promises.push(Database.getAll(dbIndex, only, i, processRow));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
async findTermsBySequence(sequence, mainDictionary) {
|
async findTermsBySequence(sequence, mainDictionary) {
|
||||||
this.validate();
|
this.validate();
|
||||||
|
|
||||||
@ -116,24 +142,24 @@ class Database {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findTermMetaBulk(terms, titles) {
|
async findTermsBySequenceBulk(sequenceList, mainDictionary) {
|
||||||
this.validate();
|
this.validate();
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
const results = [];
|
const results = [];
|
||||||
const processRow = (row, index) => {
|
const processRow = (row, index) => {
|
||||||
if (titles.includes(row.dictionary)) {
|
if (row.dictionary === mainDictionary) {
|
||||||
results.push(Database.createMeta(row, index));
|
results.push(Database.createTerm(row, index));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const db = this.db.backendDB();
|
const db = this.db.backendDB();
|
||||||
const dbTransaction = db.transaction(['termMeta'], 'readonly');
|
const dbTransaction = db.transaction(['terms'], 'readonly');
|
||||||
const dbTerms = dbTransaction.objectStore('termMeta');
|
const dbTerms = dbTransaction.objectStore('terms');
|
||||||
const dbIndex = dbTerms.index('expression');
|
const dbIndex = dbTerms.index('sequence');
|
||||||
|
|
||||||
for (let i = 0; i < terms.length; ++i) {
|
for (let i = 0; i < sequenceList.length; ++i) {
|
||||||
const only = IDBKeyRange.only(terms[i]);
|
const only = IDBKeyRange.only(sequenceList[i]);
|
||||||
promises.push(Database.getAll(dbIndex, only, i, processRow));
|
promises.push(Database.getAll(dbIndex, only, i, processRow));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +168,10 @@ class Database {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findTermMetaBulk(termList, titles) {
|
||||||
|
return this.findGenericBulk('termMeta', 'expression', termList, titles, Database.createMeta);
|
||||||
|
}
|
||||||
|
|
||||||
async findKanji(kanji, titles) {
|
async findKanji(kanji, titles) {
|
||||||
this.validate();
|
this.validate();
|
||||||
|
|
||||||
@ -155,6 +185,10 @@ class Database {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findKanjiBulk(kanjiList, titles) {
|
||||||
|
return this.findGenericBulk('kanji', 'character', kanjiList, titles, Database.createKanji);
|
||||||
|
}
|
||||||
|
|
||||||
async findKanjiMeta(kanji, titles) {
|
async findKanjiMeta(kanji, titles) {
|
||||||
this.validate();
|
this.validate();
|
||||||
|
|
||||||
@ -168,6 +202,36 @@ class Database {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findKanjiMetaBulk(kanjiList, titles) {
|
||||||
|
return this.findGenericBulk('kanjiMeta', 'character', kanjiList, titles, Database.createMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
async findGenericBulk(tableName, indexName, indexValueList, titles, createResult) {
|
||||||
|
this.validate();
|
||||||
|
|
||||||
|
const promises = [];
|
||||||
|
const results = [];
|
||||||
|
const processRow = (row, index) => {
|
||||||
|
if (titles.includes(row.dictionary)) {
|
||||||
|
results.push(createResult(row, index));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const db = this.db.backendDB();
|
||||||
|
const dbTransaction = db.transaction([tableName], 'readonly');
|
||||||
|
const dbTerms = dbTransaction.objectStore(tableName);
|
||||||
|
const dbIndex = dbTerms.index(indexName);
|
||||||
|
|
||||||
|
for (let i = 0; i < indexValueList.length; ++i) {
|
||||||
|
const only = IDBKeyRange.only(indexValueList[i]);
|
||||||
|
promises.push(Database.getAll(dbIndex, only, i, processRow));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
findTagForTitleCached(name, title) {
|
findTagForTitleCached(name, title) {
|
||||||
if (this.tagCache.hasOwnProperty(title)) {
|
if (this.tagCache.hasOwnProperty(title)) {
|
||||||
const cache = this.tagCache[title];
|
const cache = this.tagCache[title];
|
||||||
|
Loading…
Reference in New Issue
Block a user