1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.RefreshCounterCache do
6 @shortdoc "Refreshes counter cache"
10 alias Pleroma.Activity
11 alias Pleroma.CounterCache
18 Mix.Pleroma.start_pleroma()
20 ["public", "unlisted", "private", "direct"]
21 |> Enum.each(fn visibility ->
22 count = status_visibility_count_query(visibility)
23 name = "status_visibility_#{visibility}"
24 CounterCache.set(name, count)
25 Mix.Pleroma.shell_info("Set #{name} to #{count}")
28 Mix.Pleroma.shell_info("Done")
31 defp status_visibility_count_query(visibility) do
36 "activity_visibility(?, ?, ?) = ?",
43 |> where([a], fragment("(? ->> 'type'::text) = 'Create'", a.data))
44 |> Repo.aggregate(:count, :id, timeout: :timer.minutes(30))