Merge branch '502_instance_stats_active_users_count_fix' into 'develop'

[#502] Fixed `user_count` in `/api/v1/instance` to include only active local users

Closes #502

See merge request pleroma/pleroma!678
This commit is contained in:
kaniini 2019-01-17 19:27:15 +00:00
commit 98d9dcd509
3 changed files with 15 additions and 5 deletions

View file

@ -46,7 +46,7 @@ defmodule Pleroma.Stats do
from(u in User.local_user_query(), select: fragment("sum((?->>'note_count')::int)", u.info)) from(u in User.local_user_query(), select: fragment("sum((?->>'note_count')::int)", u.info))
status_count = Repo.one(status_query) status_count = Repo.one(status_query)
user_count = Repo.aggregate(User.local_user_query(), :count, :id) user_count = Repo.aggregate(User.active_local_user_query(), :count, :id)
Agent.update(__MODULE__, fn _ -> Agent.update(__MODULE__, fn _ ->
{peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}} {peers, %{domain_count: domain_count, status_count: status_count, user_count: user_count}}

View file

@ -796,7 +796,7 @@ defmodule Pleroma.User do
update_and_set_cache(cng) update_and_set_cache(cng)
end end
def local_user_query() do def local_user_query do
from( from(
u in User, u in User,
where: u.local == true, where: u.local == true,
@ -804,7 +804,14 @@ defmodule Pleroma.User do
) )
end end
def moderator_user_query() do def active_local_user_query do
from(
u in local_user_query(),
where: fragment("?->'deactivated' @> 'false'", u.info)
)
end
def moderator_user_query do
from( from(
u in User, u in User,
where: u.local == true, where: u.local == true,

View file

@ -1473,8 +1473,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end end
test "get instance information", %{conn: conn} do test "get instance information", %{conn: conn} do
insert(:user, %{local: true})
user = insert(:user, %{local: true}) user = insert(:user, %{local: true})
user2 = insert(:user, %{local: true})
{:ok, _user2} = User.deactivate(user2, !user2.info.deactivated)
insert(:user, %{local: false, nickname: "u@peer1.com"}) insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"}) insert(:user, %{local: false, nickname: "u@peer2.com"})
@ -1489,7 +1492,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
stats = result["stats"] stats = result["stats"]
assert stats assert stats
assert stats["user_count"] == 2 assert stats["user_count"] == 1
assert stats["status_count"] == 1 assert stats["status_count"] == 1
assert stats["domain_count"] == 2 assert stats["domain_count"] == 2
end end