Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
954dc4a4
Commit
954dc4a4
authored
Jan 17, 2019
by
Ivan Tashkinov
Browse files
[
#502
] Fixed `user_count` in `/api/v1/instance` to include only active local users.
parent
ce2efd1e
Changes
3
Show whitespace changes
Inline
Side-by-side
lib/pleroma/stats.ex
View file @
954dc4a4
...
...
@@ -46,7 +46,7 @@ def update_stats do
from
(
u
in
User
.
local_user_query
(),
select:
fragment
(
"sum((?->>'note_count')::int)"
,
u
.
info
))
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
_
->
{
peers
,
%{
domain_count:
domain_count
,
status_count:
status_count
,
user_count:
user_count
}}
...
...
lib/pleroma/user.ex
View file @
954dc4a4
...
...
@@ -796,7 +796,7 @@ def unblock_domain(user, domain) do
update_and_set_cache
(
cng
)
end
def
local_user_query
()
do
def
local_user_query
do
from
(
u
in
User
,
where:
u
.
local
==
true
,
...
...
@@ -804,7 +804,14 @@ def local_user_query() do
)
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
(
u
in
User
,
where:
u
.
local
==
true
,
...
...
test/web/mastodon_api/mastodon_api_controller_test.exs
View file @
954dc4a4
...
...
@@ -1473,8 +1473,11 @@ test "updates the user's banner", %{conn: conn} do
end
test
"get instance information"
,
%{
conn:
conn
}
do
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@peer2.com"
})
...
...
@@ -1489,7 +1492,7 @@ test "get instance information", %{conn: conn} do
stats
=
result
[
"stats"
]
assert
stats
assert
stats
[
"user_count"
]
==
2
assert
stats
[
"user_count"
]
==
1
assert
stats
[
"status_count"
]
==
1
assert
stats
[
"domain_count"
]
==
2
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment