diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-24 11:37:56 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-24 11:37:56 +0200 |
commit | a8f27668f247de76bf0cf301f851f50e87d7bac4 (patch) | |
tree | b6ba0eef35450b82ddb9742ce9825c091666c134 /src/api/server/ServerApi.js | |
parent | replace tar.gz dependency (deprecated) with tar (diff) | |
download | ferdium-app-a8f27668f247de76bf0cf301f851f50e87d7bac4.tar.gz ferdium-app-a8f27668f247de76bf0cf301f851f50e87d7bac4.tar.zst ferdium-app-a8f27668f247de76bf0cf301f851f50e87d7bac4.zip |
Improve recipe bulk download
Diffstat (limited to 'src/api/server/ServerApi.js')
-rw-r--r-- | src/api/server/ServerApi.js | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 8581beef7..8b0b7563c 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -447,6 +447,10 @@ export default class ServerApi { | |||
447 | 447 | ||
448 | // Helper | 448 | // Helper |
449 | async _mapServiceModels(services) { | 449 | async _mapServiceModels(services) { |
450 | const recipes = services.map(s => s.recipeId); | ||
451 | |||
452 | await this._bulkRecipeCheck(recipes); | ||
453 | |||
450 | return Promise.all(services | 454 | return Promise.all(services |
451 | .map(async service => await this._prepareServiceModel(service)) // eslint-disable-line | 455 | .map(async service => await this._prepareServiceModel(service)) // eslint-disable-line |
452 | ); | 456 | ); |
@@ -458,19 +462,8 @@ export default class ServerApi { | |||
458 | recipe = this.recipes.find(r => r.id === service.recipeId); | 462 | recipe = this.recipes.find(r => r.id === service.recipeId); |
459 | 463 | ||
460 | if (!recipe) { | 464 | if (!recipe) { |
461 | console.warn(`Recipe '${service.recipeId}' not installed, trying to fetch from server`); | 465 | console.warn(`Recipe ${service.recipeId} not loaded`); |
462 | 466 | return null; | |
463 | await this.getRecipePackage(service.recipeId); | ||
464 | |||
465 | console.debug('Rerun ServerAPI::getInstalledRecipes'); | ||
466 | await this.getInstalledRecipes(); | ||
467 | |||
468 | recipe = this.recipes.find(r => r.id === service.recipeId); | ||
469 | |||
470 | if (!recipe) { | ||
471 | console.warn(`Could not load recipe ${service.recipeId}`); | ||
472 | return null; | ||
473 | } | ||
474 | } | 467 | } |
475 | 468 | ||
476 | return new ServiceModel(service, recipe); | 469 | return new ServiceModel(service, recipe); |
@@ -480,6 +473,35 @@ export default class ServerApi { | |||
480 | } | 473 | } |
481 | } | 474 | } |
482 | 475 | ||
476 | async _bulkRecipeCheck(unfilteredRecipes) { | ||
477 | // Filter recipe duplicates as we don't need to download 3 Slack recipes | ||
478 | const recipes = unfilteredRecipes.filter((elem, pos, arr) => arr.indexOf(elem) === pos); | ||
479 | |||
480 | return Promise.all(recipes | ||
481 | .map(async (recipeId) => { | ||
482 | let recipe = this.recipes.find(r => r.id === recipeId); | ||
483 | |||
484 | if (!recipe) { | ||
485 | console.warn(`Recipe '${recipeId}' not installed, trying to fetch from server`); | ||
486 | |||
487 | await this.getRecipePackage(recipeId); | ||
488 | |||
489 | console.debug('Rerun ServerAPI::getInstalledRecipes'); | ||
490 | await this.getInstalledRecipes(); | ||
491 | |||
492 | recipe = this.recipes.find(r => r.id === recipeId); | ||
493 | |||
494 | if (!recipe) { | ||
495 | console.warn(`Could not load recipe ${recipeId}`); | ||
496 | return null; | ||
497 | } | ||
498 | } | ||
499 | |||
500 | return recipe; | ||
501 | }), | ||
502 | ).catch(err => console.error(err)); | ||
503 | } | ||
504 | |||
483 | _mapRecipePreviewModel(recipes) { | 505 | _mapRecipePreviewModel(recipes) { |
484 | return recipes.map((recipe) => { | 506 | return recipes.map((recipe) => { |
485 | try { | 507 | try { |