diff options
author | eal <eal@waifu.club> | 2018-01-14 08:15:11 +0200 |
---|---|---|
committer | eal <eal@waifu.club> | 2018-01-14 08:15:11 +0200 |
commit | d8db39564eb21d9d9b572baae1886af8d0c047d5 (patch) | |
tree | a4a6fd4ef00da7d8a78080858bf2e5a77be14f65 /lib | |
parent | 9717166d105cec6f9c878653aec2d409265e80a6 (diff) | |
download | pleroma-d8db39564eb21d9d9b572baae1886af8d0c047d5.tar.gz |
Move user count to stats agent.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/stats.ex | 13 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 11 |
2 files changed, 11 insertions, 13 deletions
diff --git a/lib/pleroma/stats.ex b/lib/pleroma/stats.ex index 45fa27b55..938e5c343 100644 --- a/lib/pleroma/stats.ex +++ b/lib/pleroma/stats.ex @@ -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 @@ defmodule Pleroma.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 diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 6ca7a6076..0615ac11a 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -93,8 +93,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController 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 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def peers(conn, _params) do - %{peers: peers} = Stats.get() - json(conn, peers) + json(conn, Stats.get_peers) end defp mastodonized_emoji do |