Move Translators.init() DB cache loop into a transaction
This commit is contained in:
parent
28fa8dd03c
commit
5b7c0a98f7
1 changed files with 123 additions and 118 deletions
|
@ -78,10 +78,10 @@ Zotero.Translators = new function() {
|
|||
|
||||
var numCached = 0;
|
||||
var filesInCache = {};
|
||||
var translatorsToCache = [];
|
||||
var translatorsDir = Zotero.getTranslatorsDirectory().path;
|
||||
var iterator = new OS.File.DirectoryIterator(translatorsDir);
|
||||
try {
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
while (true) {
|
||||
let entries = yield iterator.nextBatch(5); // TODO: adjust as necessary
|
||||
if (!entries.length) break;
|
||||
|
@ -192,18 +192,17 @@ Zotero.Translators = new function() {
|
|||
}
|
||||
|
||||
if (!dbCacheEntry) {
|
||||
yield Zotero.Translators.cacheInDB(
|
||||
translatorsToCache.push([
|
||||
fileName,
|
||||
translator.serialize(Zotero.Translator.TRANSLATOR_REQUIRED_PROPERTIES.
|
||||
concat(Zotero.Translator.TRANSLATOR_OPTIONAL_PROPERTIES)),
|
||||
lastModifiedTime
|
||||
);
|
||||
]);
|
||||
}
|
||||
|
||||
numCached++;
|
||||
}
|
||||
}
|
||||
}.bind(this))
|
||||
}
|
||||
finally {
|
||||
iterator.close();
|
||||
|
@ -218,6 +217,12 @@ Zotero.Translators = new function() {
|
|||
);
|
||||
}
|
||||
}
|
||||
yield Zotero.DB.executeTransaction(function* () {
|
||||
for (let toCache of translatorsToCache) {
|
||||
yield Zotero.Translators.cacheInDB(...toCache)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Sort by priority
|
||||
var collation = Zotero.getLocaleCollation();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue