Skip to content

Commit

Permalink
Reduce resources used on 2nd async with a semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
hackartisan committed Oct 11, 2023
1 parent 2b0e132 commit 829d66c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/services/card_image_loading_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ def import_disk(disk)
logger.info("Fetching disk #{disk} file list")
filenames = disk_array(disk)
progress_bar.total += filenames.count
Sync do |task|
Sync do
semaphore = Async::Semaphore.new(1000)
filenames.map do |file_name|
task.async do
semaphore.async do
progress_bar.increment
find_or_create_card_image(file_name)
end
Expand Down

0 comments on commit 829d66c

Please sign in to comment.