mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-04-13 14:34:14 +00:00
Merge branch 'tusooa/assign-app-user-oom' into 'develop'
Fix AssignAppUser migration OOM Closes #3358 See merge request pleroma/pleroma!4326
This commit is contained in:
commit
7943152d90
2 changed files with 12 additions and 7 deletions
1
changelog.d/assign-app-user-oom.fix
Normal file
1
changelog.d/assign-app-user-oom.fix
Normal file
|
@ -0,0 +1 @@
|
|||
Fix AssignAppUser migration OOM
|
|
@ -1,20 +1,24 @@
|
|||
defmodule Pleroma.Repo.Migrations.AssignAppUser do
|
||||
use Ecto.Migration
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.OAuth.App
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
|
||||
def up do
|
||||
Repo.all(Token)
|
||||
|> Enum.group_by(fn x -> Map.get(x, :app_id) end)
|
||||
|> Enum.each(fn {_app_id, tokens} ->
|
||||
token =
|
||||
Enum.filter(tokens, fn x -> not is_nil(x.user_id) end)
|
||||
|> List.first()
|
||||
|
||||
Token
|
||||
|> where([t], not is_nil(t.user_id))
|
||||
|> group_by([t], t.app_id)
|
||||
|> select([t], %{app_id: t.app_id, id: min(t.id)})
|
||||
|> order_by(asc: :app_id)
|
||||
|> Repo.stream()
|
||||
|> Stream.each(fn %{id: id} ->
|
||||
token = Token.Query.get_by_id(id) |> Repo.one()
|
||||
App.maybe_update_owner(token)
|
||||
end)
|
||||
|> Stream.run()
|
||||
end
|
||||
|
||||
def down, do: :ok
|
||||
|
|
Loading…
Reference in a new issue