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
d8db3956
Commit
d8db3956
authored
Jan 14, 2018
by
eal
Browse files
Move user count to stats agent.
parent
9717166d
Pipeline
#472
failed with stage
in 2 minutes and 48 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/stats.ex
View file @
d8db3956
...
...
@@ -4,13 +4,17 @@ defmodule Pleroma.Stats do
alias
Pleroma
.
{
User
,
Repo
,
Activity
}
def
start_link
do
agent
=
Agent
.
start_link
(
fn
->
%{}
end
,
name:
__MODULE__
)
agent
=
Agent
.
start_link
(
fn
->
{[],
%{}
}
end
,
name:
__MODULE__
)
schedule_update
()
agent
end
def
get
do
Agent
.
get
(
__MODULE__
,
fn
stats
->
stats
end
)
def
get_stats
do
Agent
.
get
(
__MODULE__
,
fn
{
_
,
stats
}
->
stats
end
)
end
def
get_peers
do
Agent
.
get
(
__MODULE__
,
fn
{
peers
,
_
}
->
peers
end
)
end
def
schedule_update
do
...
...
@@ -31,8 +35,9 @@ def update_stats do
where:
p
.
local
==
^
true
,
where:
fragment
(
"?->'object'->>'type' = ?"
,
p
.
data
,
^
"Note"
)
status_count
=
Repo
.
aggregate
(
status_query
,
:count
,
:id
)
user_count
=
Repo
.
aggregate
(
User
.
local_user_query
,
:count
,
:id
)
Agent
.
update
(
__MODULE__
,
fn
_
->
%
{
peers
:
peers
,
domain_count:
domain_count
,
status_count:
status_count
}
{
peers
,
%{
domain_count:
domain_count
,
status_count:
status_count
,
user_count:
user_count
}
}
end
)
end
end
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
d8db3956
...
...
@@ -93,8 +93,6 @@ def user(conn, %{"id" => id}) do
@instance
Application
.
get_env
(
:pleroma
,
:instance
)
def
masto_instance
(
conn
,
_params
)
do
user_count
=
Repo
.
aggregate
(
User
.
local_user_query
,
:count
,
:id
)
%{
domain_count:
domain_count
,
status_count:
status_count
}
=
Stats
.
get
()
response
=
%{
uri:
Web
.
base_url
,
title:
Keyword
.
get
(
@instance
,
:name
),
...
...
@@ -104,11 +102,7 @@ def masto_instance(conn, _params) do
urls:
%{
streaming_api:
String
.
replace
(
Web
.
base_url
,
[
"http"
,
"https"
],
"wss"
)
},
stats:
%{
status_count:
status_count
,
user_count:
user_count
,
domain_count:
domain_count
},
stats:
Stats
.
get_stats
,
max_toot_chars:
Keyword
.
get
(
@instance
,
:limit
)
}
...
...
@@ -116,8 +110,7 @@ def masto_instance(conn, _params) do
end
def
peers
(
conn
,
_params
)
do
%{
peers:
peers
}
=
Stats
.
get
()
json
(
conn
,
peers
)
json
(
conn
,
Stats
.
get_peers
)
end
defp
mastodonized_emoji
do
...
...
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