Explorar o código

use Set instead of object

Brian Gough %!s(int64=5) %!d(string=hai) anos
pai
achega
11ef3c27ed
Modificáronse 1 ficheiros con 8 adicións e 9 borrados
  1. 8 9
      services/clsi/app/js/OutputFileFinder.js

+ 8 - 9
services/clsi/app/js/OutputFileFinder.js

@@ -26,10 +26,9 @@ module.exports = OutputFileFinder = {
     if (callback == null) {
       callback = function (error, outputFiles, allFiles) {}
     }
-    const incomingResources = {}
-    for (const resource of Array.from(resources)) {
-      incomingResources[resource.path] = true
-    }
+    const incomingResources = new Set(
+      resources.map((resource) => resource.path)
+    )
 
     return OutputFileFinder._getAllFiles(directory, function (error, allFiles) {
       if (allFiles == null) {
@@ -41,10 +40,10 @@ module.exports = OutputFileFinder = {
       }
       const outputFiles = []
       for (const file of Array.from(allFiles)) {
-        if (!incomingResources[file]) {
+        if (!incomingResources.has(file)) {
           outputFiles.push({
             path: file,
-            type: __guard__(file.match(/\.([^\.]+)$/), (x) => x[1])
+            type: __guard__(file.match(/\.([^\.]+)$/), (x) => x[1]),
           })
         }
       }
@@ -70,7 +69,7 @@ module.exports = OutputFileFinder = {
       '.archive',
       '-o',
       '-name',
-      '.project-*'
+      '.project-*',
     ]
     const args = [
       directory,
@@ -81,7 +80,7 @@ module.exports = OutputFileFinder = {
       '-o',
       '-type',
       'f',
-      '-print'
+      '-print',
     ]
     logger.log({ args }, 'running find command')
 
@@ -105,7 +104,7 @@ module.exports = OutputFileFinder = {
       })
       return callback(null, fileList)
     })
-  }
+  },
 }
 
 function __guard__(value, transform) {