diff options
author | rinpatch <rinpatch@sdf.org> | 2019-04-18 13:10:38 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2019-04-18 13:10:38 +0300 |
commit | a11ca87f40fd85341afa4445d3b7303ae8e92b76 (patch) | |
tree | a97110a262d03e1d5de99ff0698ab666aa7592c8 /lib | |
parent | 83589ca6a56ed4ff6d7e9a116fbbf1797ba50e39 (diff) | |
download | pleroma-a11ca87f40fd85341afa4445d3b7303ae8e92b76.tar.gz |
Add a migration to remove embeded objects
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mix/tasks/compact_database.ex | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/lib/mix/tasks/compact_database.ex b/lib/mix/tasks/compact_database.ex deleted file mode 100644 index 17b9721f7..000000000 --- a/lib/mix/tasks/compact_database.ex +++ /dev/null @@ -1,57 +0,0 @@ -defmodule Mix.Tasks.CompactDatabase do - @moduledoc """ - Compact the database by flattening the object graph. - """ - - require Logger - - use Mix.Task - import Ecto.Query - alias Pleroma.Activity - alias Pleroma.Repo - - defp maybe_compact(%Activity{data: %{"object" => %{"id" => object_id}}} = activity) do - data = - activity.data - |> Map.put("object", object_id) - - {:ok, activity} = - Activity.change(activity, %{data: data}) - |> Repo.update() - - {:ok, activity} - end - - defp maybe_compact(%Activity{} = activity), do: {:ok, activity} - - defp activity_query(min_id, max_id) do - from( - a in Activity, - where: fragment("?->>'type' = 'Create'", a.data), - where: a.id >= ^min_id, - where: a.id < ^max_id - ) - end - - def run(_args) do - Application.ensure_all_started(:pleroma) - - max = Repo.aggregate(Activity, :max, :id) - Logger.info("Considering #{max} activities") - - chunks = 0..round(max / 100) - - Enum.each(chunks, fn i -> - min = i * 100 - max = min + 100 - - activity_query(min, max) - |> Repo.all() - |> Enum.each(&maybe_compact/1) - - IO.write(".") - end) - - Logger.info("Finished.") - end -end |