Merge branch '518_instance_stats_fix' into 'develop'

[#518] Fix: /api/v1/instance ("domain_count"), /api/v1/instance/peers

Closes #518

See merge request pleroma/pleroma!673
This commit is contained in:
lambda 2019-01-16 08:59:40 +00:00
commit da4b670451
2 changed files with 24 additions and 7 deletions

View file

@ -34,10 +34,11 @@ def update_stats do
peers = peers =
from( from(
u in Pleroma.User, u in Pleroma.User,
select: fragment("distinct ?->'host'", u.info), select: fragment("distinct split_part(?, '@', 2)", u.nickname),
where: u.local != ^true where: u.local != ^true
) )
|> Repo.all() |> Repo.all()
|> Enum.filter(& &1)
domain_count = Enum.count(peers) domain_count = Enum.count(peers)

View file

@ -1471,20 +1471,36 @@ test "updates the user's banner", %{conn: conn} do
test "get instance information", %{conn: conn} do test "get instance information", %{conn: conn} do
insert(:user, %{local: true}) insert(:user, %{local: true})
user = insert(:user, %{local: true}) user = insert(:user, %{local: true})
insert(:user, %{local: false}) insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"}) {:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
Pleroma.Stats.update_stats() Pleroma.Stats.update_stats()
conn = conn = get(conn, "/api/v1/instance")
conn
|> get("/api/v1/instance")
assert result = json_response(conn, 200) assert result = json_response(conn, 200)
assert result["stats"]["user_count"] == 2 stats = result["stats"]
assert result["stats"]["status_count"] == 1
assert stats
assert stats["user_count"] == 2
assert stats["status_count"] == 1
assert stats["domain_count"] == 2
end
test "get peers", %{conn: conn} do
insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})
Pleroma.Stats.update_stats()
conn = get(conn, "/api/v1/instance/peers")
assert result = json_response(conn, 200)
assert ["peer1.com", "peer2.com"] == Enum.sort(result)
end end
test "put settings", %{conn: conn} do test "put settings", %{conn: conn} do