From b425f01e60b9ea8b5164731b51337bde085306ea Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Thu, 23 May 2024 18:55:46 -0700 Subject: [PATCH] Make populate a stream with max concurrency of 1 --- server/lib/orcasite/global_setup.ex | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/lib/orcasite/global_setup.ex b/server/lib/orcasite/global_setup.ex index 38524b4c..ed844434 100644 --- a/server/lib/orcasite/global_setup.ex +++ b/server/lib/orcasite/global_setup.ex @@ -3,12 +3,16 @@ defmodule Orcasite.GlobalSetup do Orcasite.Radio.Feed |> Ash.Query.for_read(:read) |> Orcasite.Radio.read!() - |> Enum.map(fn feed -> - with {:ok, %{timestamps: timestamps}} <- Orcasite.Radio.AwsClient.list_timestamps(feed) do - timestamps - |> Enum.map(&%{feed: feed, playlist_timestamp: &1}) - |> Orcasite.Radio.bulk_create(Orcasite.Radio.FeedStream, :create) - end - end) + |> Task.async_stream( + fn feed -> + with {:ok, %{timestamps: timestamps}} <- Orcasite.Radio.AwsClient.list_timestamps(feed) do + timestamps + |> Enum.map(&%{feed: feed, playlist_timestamp: &1}) + |> Orcasite.Radio.bulk_create(Orcasite.Radio.FeedStream, :create) + end + end, + max_concurrency: 1 + ) + |> Enum.to_list() end end