aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2020-09-20 19:57:09 +0400
committerEgor Kislitsyn <egor@kislitsyn.com>2020-10-07 18:35:27 +0400
commita9efd441e242f1d8ac608b866d0cfafe4833243a (patch)
tree21fe5dd6d4c3f5a6d94df7b3b62d5598abc7c3fb /lib
parente50314d9d342dbf9a03ca484654b07717592d4bd (diff)
downloadpleroma-a9efd441e242f1d8ac608b866d0cfafe4833243a.tar.gz
Use `Pleroma.Repo.chunk_stream/2` instead of `Pleroma.RepoStreamer.chunk_stream/2`
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/backup.ex23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/pleroma/backup.ex b/lib/pleroma/backup.ex
index 242773bdb..f5f39431d 100644
--- a/lib/pleroma/backup.ex
+++ b/lib/pleroma/backup.ex
@@ -188,18 +188,17 @@ defmodule Pleroma.Backup do
with {:ok, file} <- File.open(path, [:write, :utf8]),
:ok <- write_header(file, name) do
- counter = :counters.new(1, [])
-
- query
- |> Pleroma.Repo.chunk_stream(100)
- |> Enum.each(fn i ->
- with {:ok, str} <- fun.(i),
- :ok <- IO.write(file, str <> ",\n") do
- :counters.add(counter, 1, 1)
- end
- end)
-
- total = :counters.get(counter, 1)
+ total =
+ query
+ |> Pleroma.Repo.chunk_stream(100)
+ |> Enum.reduce(0, fn i, acc ->
+ with {:ok, str} <- fun.(i),
+ :ok <- IO.write(file, str <> ",\n") do
+ acc + 1
+ else
+ _ -> acc
+ end
+ end)
with :ok <- :file.pwrite(file, {:eof, -2}, "\n],\n \"totalItems\": #{total}}") do
File.close(file)