@@ -8,6 +8,8 @@ defmodule Octocon.Workers.PluralKitImportWorker do
88 - `pk_token` (binary): The PluralKit API token to use for the request.
99 """
1010
11+ @ insert_concurrency 10
12+
1113 alias Octocon . {
1214 Accounts ,
1315 Alters ,
@@ -53,45 +55,39 @@ defmodule Octocon.Workers.PluralKitImportWorker do
5355
5456 alter_count = length ( alters )
5557
56- chunked_alters =
57- alters
58- |> Stream . map (
59- & Map . drop ( & 1 , [ :__meta__ , :__struct__ , :fronts , :user , :global_journals , :tags ] )
60- )
61- |> Enum . chunk_every ( 1000 )
62-
63- Repo . transaction ( fn ->
64- chunked_alters
65- |> Enum . each ( fn chunk ->
66- Repo . insert_all_regional ( Alter , chunk , { :user , { :system , system_id } } )
67- end )
58+ alters
59+ |> Task . async_stream (
60+ & Repo . insert_regional ( & 1 , { :user , { :system , system_id } } ) ,
61+ max_concurrency: @ insert_concurrency ,
62+ ordered: false
63+ )
64+ |> Stream . run ( )
6865
69- user = Accounts . get_user! ( { :system , system_id } )
66+ user = Accounts . get_user! ( { :system , system_id } )
7067
71- Accounts . update_user (
72- user ,
73- % {
74- lifetime_alter_count: user . lifetime_alter_count + alter_count ,
75- description: default_if_empty ( description , 3000 , user . description )
76- }
77- )
78-
79- Accounts . update_discord_settings (
80- user ,
81- % {
82- system_tag:
83- default_if_empty (
84- system_tag ,
85- 20 ,
86- Map . get (
87- user . discord_settings || % Octocon.Accounts.DiscordSettings { } ,
88- :system_tag ,
89- nil
90- )
68+ Accounts . update_user (
69+ user ,
70+ % {
71+ lifetime_alter_count: user . lifetime_alter_count + alter_count ,
72+ description: default_if_empty ( description , 3000 , user . description )
73+ }
74+ )
75+
76+ Accounts . update_discord_settings (
77+ user ,
78+ % {
79+ system_tag:
80+ default_if_empty (
81+ system_tag ,
82+ 20 ,
83+ Map . get (
84+ user . discord_settings || % Octocon.Accounts.DiscordSettings { } ,
85+ :system_tag ,
86+ nil
9187 )
92- }
93- )
94- end )
88+ )
89+ }
90+ )
9591
9692 OctoconWeb.Endpoint . broadcast! ( "system:#{ system_id } " , "alters_created" , % {
9793 alters: Enum . map ( alters , & OctoconWeb.System.AlterJSON . data_me ( & 1 ) )
0 commit comments