forked from AkkomaGang/akkoma
Add a task to re-count statuses for all users
This commit is contained in:
parent
6355694309
commit
d537bfd4e1
3 changed files with 62 additions and 0 deletions
|
@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- OAuth: support for hierarchical permissions / [Mastodon 2.4.3 OAuth permissions](https://docs.joinmastodon.org/api/permissions/)
|
||||
- Authentication: Added rate limit for password-authorized actions / login existence checks
|
||||
- Metadata Link: Atom syndication Feed
|
||||
- Mix task to re-count statuses for all users (`mix pleroma.count_statuses`)
|
||||
|
||||
### Changed
|
||||
- **Breaking:** Elixir >=1.8 is now required (was >= 1.7)
|
||||
|
|
22
lib/mix/tasks/pleroma/count_statuses.ex
Normal file
22
lib/mix/tasks/pleroma/count_statuses.ex
Normal file
|
@ -0,0 +1,22 @@
|
|||
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
|
39
test/tasks/count_statuses_test.exs
Normal file
39
test/tasks/count_statuses_test.exs
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.CountStatusesTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import ExUnit.CaptureIO, only: [capture_io: 1]
|
||||
import Pleroma.Factory
|
||||
|
||||
test "counts statuses" do
|
||||
user = insert(:user)
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "test"})
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "test2"})
|
||||
|
||||
user2 = insert(:user)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "test3"})
|
||||
|
||||
user = refresh_record(user)
|
||||
user2 = refresh_record(user2)
|
||||
|
||||
assert %{info: %{note_count: 2}} = user
|
||||
assert %{info: %{note_count: 1}} = user2
|
||||
|
||||
{:ok, user} = User.update_info(user, &User.Info.set_note_count(&1, 0))
|
||||
{:ok, user2} = User.update_info(user2, &User.Info.set_note_count(&1, 0))
|
||||
|
||||
assert %{info: %{note_count: 0}} = user
|
||||
assert %{info: %{note_count: 0}} = user2
|
||||
|
||||
assert capture_io(fn -> Mix.Tasks.Pleroma.CountStatuses.run([]) end) == "Done\n"
|
||||
|
||||
assert %{info: %{note_count: 2}} = refresh_record(user)
|
||||
assert %{info: %{note_count: 1}} = refresh_record(user2)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue