Skip to content

Commit 0b6c579

Browse files
Merge pull request #22 from SocketDev/mik-fix-on2
Fix quadratic time look up in find_files
2 parents 0255e26 + 1fca2e8 commit 0b6c579

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

socketsecurity/core/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def find_files(path: str) -> list:
415415
"""
416416
log.debug("Starting Find Files")
417417
start_time = time.time()
418-
files = []
418+
files = set()
419419
for ecosystem in socket_globs:
420420
patterns = socket_globs[ecosystem]
421421
for file_name in patterns:
@@ -427,7 +427,7 @@ def find_files(path: str) -> list:
427427
glob_files = glob(file_path, recursive=True)
428428
for glob_file in glob_files:
429429
if glob_file not in files:
430-
files.append(glob_file)
430+
files.add(glob_file)
431431
glob_end = time.time()
432432
glob_total_time = glob_end - glob_start
433433
log.debug(f"Glob for pattern {file_path} took {glob_total_time:.2f} seconds")
@@ -436,7 +436,7 @@ def find_files(path: str) -> list:
436436
end_time = time.time()
437437
total_time = end_time - start_time
438438
log.info(f"Found {len(files)} in {total_time:.2f} seconds")
439-
return files
439+
return list(files)
440440

441441
@staticmethod
442442
def create_full_scan(files: list, params: FullScanParams, workspace: str) -> FullScan:
@@ -594,13 +594,13 @@ def compare_sboms(new_scan: list, head_scan: list) -> Diff:
594594
head_packages = Core.create_sbom_dict(head_scan)
595595
new_scan_alerts = {}
596596
head_scan_alerts = {}
597-
consolidated = []
597+
consolidated = set()
598598
for package_id in new_packages:
599599
purl, package = Core.create_purl(package_id, new_packages)
600600
base_purl = f"{purl.ecosystem}/{purl.name}@{purl.version}"
601601
if package_id not in head_packages and package.direct and base_purl not in consolidated:
602602
diff.new_packages.append(purl)
603-
consolidated.append(base_purl)
603+
consolidated.add(base_purl)
604604
new_scan_alerts = Core.create_issue_alerts(package, new_scan_alerts, new_packages)
605605
for package_id in head_packages:
606606
purl, package = Core.create_purl(package_id, head_packages)

0 commit comments

Comments
 (0)