summaryrefslogtreecommitdiff
path: root/lib/mix/tasks/pleroma/count_statuses.ex
blob: 8761d8f17e621aed500ce4302c115bfe5bc6eb7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Mix.Tasks.Pleroma.CountStatuses do
  @shortdoc "Re-counts statuses for all users"

  use Mix.Task
  alias Pleroma.User
  import Ecto.Query

  def run([]) do
    Mix.Pleroma.start_pleroma()

    stream =
      User
      |> where(local: true)
      |> Pleroma.Repo.stream()

    Pleroma.Repo.transaction(fn ->
      Enum.each(stream, &User.update_note_count/1)
    end)

    Mix.Pleroma.shell_info("Done")
  end
end