From 6982b2d5e82af73e44b37b0274a07dc2c2d824d3 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 15 Apr 2024 21:53:01 +0200 Subject: [PATCH] refactor: do not enqueue antivirus job for safe blob --- app/models/concerns/attachment_virus_scanner_concern.rb | 9 ++++++++- spec/system/instructeurs/instruction_spec.rb | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/attachment_virus_scanner_concern.rb b/app/models/concerns/attachment_virus_scanner_concern.rb index 217d5e920..832d15a98 100644 --- a/app/models/concerns/attachment_virus_scanner_concern.rb +++ b/app/models/concerns/attachment_virus_scanner_concern.rb @@ -15,6 +15,13 @@ module AttachmentVirusScannerConcern private def scan_for_virus_later - blob&.scan_for_virus_later + return if blob.nil? + + # do not scan if the blob is already marked as safe + # usually because of metadata[:virus_scan_result] = ActiveStorage::VirusScanner::SAFE + # added on a blob built by the application itself + return if blob.virus_scan_result == ActiveStorage::VirusScanner::SAFE + + blob.scan_for_virus_later end end diff --git a/spec/system/instructeurs/instruction_spec.rb b/spec/system/instructeurs/instruction_spec.rb index a826596dd..d6230e9b5 100644 --- a/spec/system/instructeurs/instruction_spec.rb +++ b/spec/system/instructeurs/instruction_spec.rb @@ -139,7 +139,7 @@ describe 'Instructing a dossier:', js: true do expect(page).to have_text("Export .csv d’un dossier « à suivre » demandé il y a moins d'une minute") expect(page).to have_text("En préparation") - assert_performed_jobs 2 do + assert_performed_jobs 1 do perform_enqueued_jobs(only: ExportJob) end