diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-07-31 14:46:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-31 14:46:09 -0400 |
commit | 8c4a50f68c9543c14cfe76abd2f6f42135b0e13d (patch) | |
tree | 9c7f252952a37b117f298b9b08a6c07418049c7f /ext/js/pages/settings/dictionary-import-controller.js | |
parent | 992c8bcf75b9477e1652cf2a458418e375903cc0 (diff) |
DictionaryImporterThreaded (#1865)
* Create new classes for importing dictionaries from a separate thread
* Use threaded importer
* Update worker tests
Diffstat (limited to 'ext/js/pages/settings/dictionary-import-controller.js')
-rw-r--r-- | ext/js/pages/settings/dictionary-import-controller.js | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js index 128e18cb..5e51a48a 100644 --- a/ext/js/pages/settings/dictionary-import-controller.js +++ b/ext/js/pages/settings/dictionary-import-controller.js @@ -17,9 +17,7 @@ /* global * DictionaryController - * DictionaryDatabase - * DictionaryImporter - * DictionaryImporterMediaLoader + * DictionaryImporterThreaded */ class DictionaryImportController { @@ -183,22 +181,16 @@ class DictionaryImportController { } async _importDictionary(file, importDetails, onProgress) { - const dictionaryDatabase = await this._getPreparedDictionaryDatabase(); - try { - const dictionaryImporterMediaLoader = new DictionaryImporterMediaLoader(); - const dictionaryImporter = new DictionaryImporter(dictionaryImporterMediaLoader); - const archiveContent = await this._readFile(file); - const {result, errors} = await dictionaryImporter.importDictionary(dictionaryDatabase, archiveContent, importDetails, onProgress); - yomichan.api.triggerDatabaseUpdated('dictionary', 'import'); - const errors2 = await this._addDictionarySettings(result.sequenced, result.title); - - if (errors.length > 0) { - const allErrors = [...errors, ...errors2]; - allErrors.push(new Error(`Dictionary may not have been imported properly: ${allErrors.length} error${allErrors.length === 1 ? '' : 's'} reported.`)); - this._showErrors(allErrors); - } - } finally { - dictionaryDatabase.close(); + const dictionaryImporter = new DictionaryImporterThreaded(); + const archiveContent = await this._readFile(file); + const {result, errors} = await dictionaryImporter.importDictionary(archiveContent, importDetails, onProgress); + yomichan.api.triggerDatabaseUpdated('dictionary', 'import'); + const errors2 = await this._addDictionarySettings(result.sequenced, result.title); + + if (errors.length > 0) { + const allErrors = [...errors, ...errors2]; + allErrors.push(new Error(`Dictionary may not have been imported properly: ${allErrors.length} error${allErrors.length === 1 ? '' : 's'} reported.`)); + this._showErrors(allErrors); } } @@ -311,12 +303,6 @@ class DictionaryImportController { } } - async _getPreparedDictionaryDatabase() { - const dictionaryDatabase = new DictionaryDatabase(); - await dictionaryDatabase.prepare(); - return dictionaryDatabase; - } - async _modifyGlobalSettings(targets) { const results = await this._settingsController.modifyGlobalSettings(targets); const errors = []; |