44 "fmt"
55 "log/slog"
66 "math"
7- "math/rand/v2"
87 "net/http"
98 "strings"
109 "time"
@@ -223,8 +222,8 @@ func (s *service) HandleScanResult(asset models.Asset, assetVersion *models.Asse
223222func (s * service ) handleScanResult (userID string , scannerID string , assetVersion * models.AssetVersion , dependencyVulns []models.DependencyVuln , doRiskManagement bool , asset models.Asset ) (int , int , []models.DependencyVuln , error ) {
224223 // get all existing dependencyVulns from the database - this is the old state
225224
226- number := rand .IntN (len (dependencyVulns ))
227- dependencyVulns = dependencyVulns [:number ]
225+ // number := rand.IntN(len(dependencyVulns))
226+ // dependencyVulns = dependencyVulns[:0 ]
228227 scannerID = scannerID + " "
229228 existingDependencyVulns , err := s .dependencyVulnRepository .ListByAssetAndAssetVersion (assetVersion .Name , assetVersion .AssetID )
230229 if err != nil {
@@ -245,8 +244,8 @@ func (s *service) handleScanResult(userID string, scannerID string, assetVersion
245244 foundByScannerAndExisting := comparison .InBoth //We have to check if it was already found by this scanner or only by other scanners
246245 notFoundByScannerAndExisting := comparison .OnlyInA //We have to update all vulnerabilities which were previously found by this scanner and now aren't
247246
248- var vulnerabilitiesToFix []models.DependencyVuln //We should collect all vulnerabilities we want to fix so we can do it all at once
249- var vulnerabilitiesToUpdate []models.DependencyVuln
247+ var vulnerabilitiesToFix []models.DependencyVuln //We should collect all vulnerabilities we want to fix so we can do it all at once
248+ var vulnerabilitiesToUpdate []models.DependencyVuln //We should do the same
250249 // get a transaction
251250 if err := s .dependencyVulnRepository .Transaction (func (tx core.DB ) error {
252251 // We can create the newly found one without checking anything
@@ -257,12 +256,12 @@ func (s *service) handleScanResult(userID string, scannerID string, assetVersion
257256 // Now we work on the vulnerabilities found in both sets -> has the vulnerability this scanner id already in his scanner_ids
258257 for i := range foundByScannerAndExisting {
259258 if ! strings .Contains (foundByScannerAndExisting [i ].ScannerID , scannerID ) {
260- fmt .Printf ("\n The Scanner ID before : %s\n " , foundByScannerAndExisting [i ].ScannerID )
261259 foundByScannerAndExisting [i ].ScannerID = foundByScannerAndExisting [i ].ScannerID + scannerID
262- fmt .Printf ("\n The Scanner ID after : %s\n " , foundByScannerAndExisting [i ].ScannerID )
263260 }
264261 }
262+
265263 err := s .dependencyVulnRepository .SaveBatch (tx , foundByScannerAndExisting )
264+
266265 if err != nil {
267266 slog .Error ("error when trying to update vulnerabilities" )
268267 return err
0 commit comments