File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed
services/app/apps/codebattle Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,15 @@ defmodule Codebattle.Utils.PopulateUsers do
44 def from_csv ( file ) do
55 utc_now = NaiveDateTime . utc_now ( ) |> NaiveDateTime . truncate ( :second )
66
7- users =
8- File . stream! ( file )
9- |> NimbleCSV.RFC4180 . parse_stream ( )
10- |> Stream . map ( & row_to_user ( & 1 , utc_now ) )
11- |> Enum . to_list ( )
7+ File . stream! ( file )
8+ |> NimbleCSV.RFC4180 . parse_stream ( )
9+ |> Stream . chunk_every ( 500 )
10+ |> Stream . each ( & process_batch ( & 1 , utc_now ) )
11+ |> Stream . run ( )
12+ end
1213
14+ defp process_batch ( users , now ) do
15+ users = Enum . map ( users , & row_to_user ( & 1 , now ) )
1316 Codebattle.Repo . insert_all ( Codebattle.User , users )
1417 end
1518
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ defmodule Codebattle.Utils.PopulateUsersTest do
1414 IO . write ( fd , csv )
1515 File . close ( fd )
1616
17- assert { 4 , nil } = Codebattle.Utils.PopulateUsers . from_csv ( path )
17+ assert :ok = Codebattle.Utils.PopulateUsers . from_csv ( path )
1818 assert % { name: "user1" } = Codebattle.User . authenticate ( "user1" , "p@ssw0rd!" )
1919 end
2020end
You can’t perform that action at this time.
0 commit comments