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 794497f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/services/card_image_loading_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(logger: nil, suppress_progress: false)
def import
barrier = Async::Barrier.new
Sync do
semaphore = Async::Semaphore.new(8, parent: barrier)
semaphore = Async::Semaphore.new(22, parent: barrier)

(1..22).map do |disk|
semaphore.async do
Expand All @@ -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(10_000)
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 794497f

Please sign in to comment.