small refactoring

This commit is contained in:
Maksim Pechnikov 2020-09-17 09:13:43 +03:00
parent b867f9d7ae
commit 5a8ea0a5b0
2 changed files with 5 additions and 34 deletions

View File

@ -65,20 +65,14 @@ defp handle_error(op, user_id, error) do
def blocks_import(%User{} = blocker, [_ | _] = identifiers) do def blocks_import(%User{} = blocker, [_ | _] = identifiers) do
BackgroundWorker.enqueue( BackgroundWorker.enqueue(
"blocks_import", "blocks_import",
%{ %{"user_id" => blocker.id, "identifiers" => identifiers}
"blocker_id" => blocker.id,
"blocked_identifiers" => identifiers
}
) )
end end
def follow_import(%User{} = follower, [_ | _] = identifiers) do def follow_import(%User{} = follower, [_ | _] = identifiers) do
BackgroundWorker.enqueue( BackgroundWorker.enqueue(
"follow_import", "follow_import",
%{ %{"user_id" => follower.id, "identifiers" => identifiers}
"follower_id" => follower.id,
"followed_identifiers" => identifiers
}
) )
end end

View File

@ -26,33 +26,10 @@ def perform(%Job{args: %{"op" => "force_password_reset", "user_id" => user_id}})
User.perform(:force_password_reset, user) User.perform(:force_password_reset, user)
end end
def perform(%Job{ def perform(%Job{args: %{"op" => op, "user_id" => user_id, "identifiers" => identifiers}})
args: %{ when op in ["blocks_import", "follow_import", "mutes_import"] do
"op" => "blocks_import",
"blocker_id" => blocker_id,
"blocked_identifiers" => blocked_identifiers
}
}) do
blocker = User.get_cached_by_id(blocker_id)
{:ok, User.Import.perform(:blocks_import, blocker, blocked_identifiers)}
end
def perform(%Job{
args: %{
"op" => "follow_import",
"follower_id" => follower_id,
"followed_identifiers" => followed_identifiers
}
}) do
follower = User.get_cached_by_id(follower_id)
{:ok, User.Import.perform(:follow_import, follower, followed_identifiers)}
end
def perform(%Job{
args: %{"op" => "mutes_import", "user_id" => user_id, "identifiers" => identifiers}
}) do
user = User.get_cached_by_id(user_id) user = User.get_cached_by_id(user_id)
{:ok, User.Import.perform(:mutes_import, user, identifiers)} {:ok, User.Import.perform(String.to_atom(op), user, identifiers)}
end end
def perform(%Job{args: %{"op" => "media_proxy_preload", "message" => message}}) do def perform(%Job{args: %{"op" => "media_proxy_preload", "message" => message}}) do