Expose more statistics
* differenciate local & all events/comments/groups * add instance follows/followings Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -12,9 +12,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Statistics do
|
||||
{:ok,
|
||||
%{
|
||||
number_of_users: StatisticsModule.get_cached_value(:local_users),
|
||||
number_of_events: StatisticsModule.get_cached_value(:local_events),
|
||||
number_of_comments: StatisticsModule.get_cached_value(:local_comments),
|
||||
number_of_groups: StatisticsModule.get_cached_value(:local_groups)
|
||||
number_of_events: StatisticsModule.get_cached_value(:federation_events),
|
||||
number_of_local_events: StatisticsModule.get_cached_value(:local_events),
|
||||
number_of_comments: StatisticsModule.get_cached_value(:federation_comments),
|
||||
number_of_local_comments: StatisticsModule.get_cached_value(:local_comments),
|
||||
number_of_groups: StatisticsModule.get_cached_value(:federation_groups),
|
||||
number_of_local_groups: StatisticsModule.get_cached_value(:local_groups),
|
||||
number_of_instance_followings: StatisticsModule.get_cached_value(:instance_followings),
|
||||
number_of_instance_followers: StatisticsModule.get_cached_value(:instance_followers)
|
||||
}}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,9 +10,20 @@ defmodule Mobilizon.GraphQL.Schema.StatisticsType do
|
||||
object :statistics do
|
||||
# Instance name
|
||||
field(:number_of_users, :integer, description: "The number of local users")
|
||||
field(:number_of_events, :integer, description: "The number of local events")
|
||||
field(:number_of_comments, :integer, description: "The number of local comments")
|
||||
field(:number_of_groups, :integer, description: "The number of local groups")
|
||||
field(:number_of_events, :integer, description: "The total number of events")
|
||||
field(:number_of_local_events, :integer, description: "The number of local events")
|
||||
field(:number_of_comments, :integer, description: "The total number of comments")
|
||||
field(:number_of_local_comments, :integer, description: "The number of local events")
|
||||
field(:number_of_groups, :integer, description: "The total number of groups")
|
||||
field(:number_of_local_groups, :integer, description: "The number of local groups")
|
||||
|
||||
field(:number_of_instance_followers, :integer,
|
||||
description: "The number of this instance's followers"
|
||||
)
|
||||
|
||||
field(:number_of_instance_followings, :integer,
|
||||
description: "The number of instances this instance follows"
|
||||
)
|
||||
end
|
||||
|
||||
object :statistics_queries do
|
||||
|
||||
@@ -1076,6 +1076,17 @@ defmodule Mobilizon.Actors do
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the number of followers for an actor
|
||||
"""
|
||||
@spec count_followers_for_actor(Actor.t()) :: integer()
|
||||
def count_followers_for_actor(%Actor{id: actor_id}) do
|
||||
actor_id
|
||||
|> follower_for_actor_query()
|
||||
|> where(approved: true)
|
||||
|> Repo.aggregate(:count)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of followings for an actor.
|
||||
If actor A follows actor B and C, actor A's followings are B and C.
|
||||
@@ -1087,6 +1098,17 @@ defmodule Mobilizon.Actors do
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the number of followings for an actor
|
||||
"""
|
||||
@spec count_followings_for_actor(Actor.t()) :: integer()
|
||||
def count_followings_for_actor(%Actor{id: actor_id}) do
|
||||
actor_id
|
||||
|> followings_for_actor_query()
|
||||
|> where(approved: true)
|
||||
|> Repo.aggregate(:count)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of external followings for an actor.
|
||||
"""
|
||||
|
||||
@@ -4,6 +4,7 @@ defmodule Mobilizon.Service.Statistics do
|
||||
"""
|
||||
|
||||
alias Mobilizon.{Actors, Discussions, Events, Users}
|
||||
alias Mobilizon.Federation.ActivityPub.Relay
|
||||
|
||||
def get_cached_value(key) do
|
||||
case Cachex.fetch(:statistics, key, fn key ->
|
||||
@@ -44,4 +45,14 @@ defmodule Mobilizon.Service.Statistics do
|
||||
defp create_cache(:federation_groups) do
|
||||
Actors.count_groups()
|
||||
end
|
||||
|
||||
defp create_cache(:instance_followers) do
|
||||
relay_actor = Relay.get_actor()
|
||||
Actors.count_followers_for_actor(relay_actor)
|
||||
end
|
||||
|
||||
defp create_cache(:instance_followings) do
|
||||
relay_actor = Relay.get_actor()
|
||||
Actors.count_followings_for_actor(relay_actor)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user