Use Pleroma.Repo.chunk_stream/2 instead of Pleroma.RepoStreamer.chunk_stream/2

This commit is contained in:
Egor Kislitsyn 2020-09-20 19:57:09 +04:00
parent e50314d9d3
commit a9efd441e2
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805

View File

@ -188,18 +188,17 @@ defmodule Pleroma.Backup do
with {:ok, file} <- File.open(path, [:write, :utf8]), with {:ok, file} <- File.open(path, [:write, :utf8]),
:ok <- write_header(file, name) do :ok <- write_header(file, name) do
counter = :counters.new(1, []) total =
query
query |> Pleroma.Repo.chunk_stream(100)
|> Pleroma.Repo.chunk_stream(100) |> Enum.reduce(0, fn i, acc ->
|> Enum.each(fn i -> with {:ok, str} <- fun.(i),
with {:ok, str} <- fun.(i), :ok <- IO.write(file, str <> ",\n") do
:ok <- IO.write(file, str <> ",\n") do acc + 1
:counters.add(counter, 1, 1) else
end _ -> acc
end) end
end)
total = :counters.get(counter, 1)
with :ok <- :file.pwrite(file, {:eof, -2}, "\n],\n \"totalItems\": #{total}}") do with :ok <- :file.pwrite(file, {:eof, -2}, "\n],\n \"totalItems\": #{total}}") do
File.close(file) File.close(file)