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 numCached = 0;
|
||||||
var filesInCache = {};
|
var filesInCache = {};
|
||||||
|
var translatorsToCache = [];
|
||||||
var translatorsDir = Zotero.getTranslatorsDirectory().path;
|
var translatorsDir = Zotero.getTranslatorsDirectory().path;
|
||||||
var iterator = new OS.File.DirectoryIterator(translatorsDir);
|
var iterator = new OS.File.DirectoryIterator(translatorsDir);
|
||||||
try {
|
try {
|
||||||
yield Zotero.DB.executeTransaction(function* () {
|
|
||||||
while (true) {
|
while (true) {
|
||||||
let entries = yield iterator.nextBatch(5); // TODO: adjust as necessary
|
let entries = yield iterator.nextBatch(5); // TODO: adjust as necessary
|
||||||
if (!entries.length) break;
|
if (!entries.length) break;
|
||||||
|
@ -192,18 +192,17 @@ Zotero.Translators = new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dbCacheEntry) {
|
if (!dbCacheEntry) {
|
||||||
yield Zotero.Translators.cacheInDB(
|
translatorsToCache.push([
|
||||||
fileName,
|
fileName,
|
||||||
translator.serialize(Zotero.Translator.TRANSLATOR_REQUIRED_PROPERTIES.
|
translator.serialize(Zotero.Translator.TRANSLATOR_REQUIRED_PROPERTIES.
|
||||||
concat(Zotero.Translator.TRANSLATOR_OPTIONAL_PROPERTIES)),
|
concat(Zotero.Translator.TRANSLATOR_OPTIONAL_PROPERTIES)),
|
||||||
lastModifiedTime
|
lastModifiedTime
|
||||||
);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
numCached++;
|
numCached++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.bind(this))
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
iterator.close();
|
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
|
// Sort by priority
|
||||||
var collation = Zotero.getLocaleCollation();
|
var collation = Zotero.getLocaleCollation();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue