Merge branch 'db-fixes' into 'main'

Add appropriate timeouts for Repo.transactions

See merge request framasoft/mobilizon!1227
This commit is contained in:
Thomas Citharel 2022-05-04 06:58:17 +00:00
commit a400499a57
4 changed files with 67 additions and 58 deletions

View File

@ -64,7 +64,7 @@ defmodule Mobilizon.Service.ActorSuspension do
Logger.debug("Going to run the transaction") Logger.debug("Going to run the transaction")
case Repo.transaction(multi) do case Repo.transaction(multi, timeout: 60_000) do
{:ok, %{actor: %Actor{} = actor}} -> {:ok, %{actor: %Actor{} = actor}} ->
{:ok, true} = Cachex.del(:activity_pub, "actor_#{actor.preferred_username}") {:ok, true} = Cachex.del(:activity_pub, "actor_#{actor.preferred_username}")
Cachable.clear_all_caches(actor) Cachable.clear_all_caches(actor)

View File

@ -29,7 +29,8 @@ defmodule Mobilizon.Service.SiteMap do
gzip: false gzip: false
] ]
Repo.transaction(fn -> Repo.transaction(
fn ->
Events.stream_events_for_sitemap() Events.stream_events_for_sitemap()
|> Stream.concat(Actors.list_groups_for_stream()) |> Stream.concat(Actors.list_groups_for_stream())
|> Stream.concat(Posts.list_posts_for_stream()) |> Stream.concat(Posts.list_posts_for_stream())
@ -57,7 +58,9 @@ defmodule Mobilizon.Service.SiteMap do
|> Sitemapper.persist(config) |> Sitemapper.persist(config)
|> Sitemapper.ping(config) |> Sitemapper.ping(config)
|> Stream.run() |> Stream.run()
end) end,
timeout: :infinity
)
end end
# Sometimes we use naive datetimes # Sometimes we use naive datetimes

View File

@ -20,7 +20,8 @@ defmodule Mobilizon.Service.Workers.SendActivityRecapWorker do
@impl Oban.Worker @impl Oban.Worker
def perform(%Job{}) do def perform(%Job{}) do
Repo.transaction(fn -> Repo.transaction(
fn ->
Users.stream_users_for_recap() Users.stream_users_for_recap()
|> Enum.to_list() |> Enum.to_list()
|> Repo.preload([:settings, :activity_settings]) |> Repo.preload([:settings, :activity_settings])
@ -40,7 +41,9 @@ defmodule Mobilizon.Service.Workers.SendActivityRecapWorker do
} -> } ->
Email.send(user, activities, recap: group_notifications) Email.send(user, activities, recap: group_notifications)
end) end)
end) end,
timeout: :infinity
)
end end
defp activities_for_user( defp activities_for_user(

View File

@ -82,7 +82,8 @@ defmodule Mobilizon.Web.Email.Event do
|> MapSet.new() |> MapSet.new()
if MapSet.size(diff) > 0 do if MapSet.size(diff) > 0 do
Repo.transaction(fn -> Repo.transaction(
fn ->
event_id event_id
|> Events.list_local_emails_user_participants_for_event_query() |> Events.list_local_emails_user_participants_for_event_query()
|> Repo.stream() |> Repo.stream()
@ -90,7 +91,9 @@ defmodule Mobilizon.Web.Email.Event do
|> Enum.each( |> Enum.each(
&send_notification_for_event_update_to_participant(&1, old_event, event, diff) &send_notification_for_event_update_to_participant(&1, old_event, event, diff)
) )
end) end,
timeout: 120_000
)
else else
{:ok, :ok} {:ok, :ok}
end end