diff options
| author | Alex S <alex.strizhakov@gmail.com> | 2019-04-15 11:43:02 +0700 | 
|---|---|---|
| committer | Alex S <alex.strizhakov@gmail.com> | 2019-04-25 13:40:12 +0700 | 
| commit | 6322c1e123c102d603bd9f6e8bd443568c2fd1cb (patch) | |
| tree | 1bcef031a8ccd954aec91459ee64aa5658b637b1 /priv | |
| parent | 17b5b78737c4412676a7199248943c23c0be23df (diff) | |
| download | pleroma-6322c1e123c102d603bd9f6e8bd443568c2fd1cb.tar.gz pleroma-6322c1e123c102d603bd9f6e8bd443568c2fd1cb.zip | |
migration optimization
changelog wording
Diffstat (limited to 'priv')
| -rw-r--r-- | priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs | 20 | 
1 files changed, 15 insertions, 5 deletions
| diff --git a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs index 1930fc3cf..c30c302f7 100644 --- a/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs +++ b/priv/repo/migrations/20190414125034_migrate_old_bookmarks.exs @@ -1,16 +1,26 @@  defmodule Pleroma.Repo.Migrations.MigrateOldBookmarks do    use Ecto.Migration +  import Ecto.Query    alias Pleroma.Activity    alias Pleroma.Bookmark    alias Pleroma.User    alias Pleroma.Repo    def up do -    Repo.all(User) -    |> Enum.each(fn user -> -      Enum.each(user.old_bookmarks, fn id -> -        activity = Activity.get_create_by_object_ap_id(id) -        {:ok, _} = Bookmark.create(user.id, activity.id) +    query = +      from(u in User, +        where: u.local == true, +        where: fragment("array_length(?, 1)", u.old_bookmarks) > 0, +        select: %{id: u.id, old_bookmarks: u.old_bookmarks} +      ) + +    Repo.transaction(fn -> +      Repo.stream(query) +      |> Enum.each(fn user -> +        Enum.each(user.old_bookmarks, fn id -> +          activity = Activity.get_create_by_object_ap_id(id) +          {:ok, _} = Bookmark.create(user.id, activity.id) +        end)        end)      end)    end | 
