Parcourir la source

use Promise.all

utsushiiro il y a 7 ans
Parent
commit
77abea8cac
1 fichiers modifiés avec 9 ajouts et 5 suppressions
  1. 9 5
      src/server/service/config-manager.js

+ 9 - 5
src/server/service/config-manager.js

@@ -106,13 +106,17 @@ class ConfigManager {
    * ```
    * ```
    */
    */
   async updateConfigs(configs) {
   async updateConfigs(configs) {
+    const results = [];
     for (const config of configs) {
     for (const config of configs) {
-      await this.configModel.findOneAndUpdate(
-        { ns: config.ns, key: config.key },
-        { ns: config.ns, key: config.key, value: JSON.stringify(config.value) },
-        { upsert: true, }
-      ).exec();
+      results.push(
+        this.configModel.findOneAndUpdate(
+          { ns: config.ns, key: config.key },
+          { ns: config.ns, key: config.key, value: JSON.stringify(config.value) },
+          { upsert: true, }
+        ).exec()
+      );
     }
     }
+    await Promise.all(results);
 
 
     await this.loadConfigs();
     await this.loadConfigs();
   }
   }