Improve dashboard

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-10-15 11:04:05 +02:00
parent dacec2672b
commit f6480cb37e
10 changed files with 163 additions and 34 deletions

View File

@@ -178,13 +178,25 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
_ -> nil
end
last_group_created =
case Actors.list_actors(:Group) do
%Page{elements: [group | _]} -> group
_ -> nil
end
{:ok,
%{
number_of_users: Statistics.get_cached_value(:local_users),
number_of_events: Statistics.get_cached_value(:local_events),
number_of_groups: Statistics.get_cached_value(:local_groups),
number_of_comments: Statistics.get_cached_value(:local_comments),
number_of_confirmed_participations_to_local_events:
Statistics.get_cached_value(:confirmed_participations_to_local_events),
number_of_reports: Mobilizon.Reports.count_opened_reports(),
last_public_event_published: last_public_event_published
number_of_followers: Statistics.get_cached_value(:instance_followers),
number_of_followings: Statistics.get_cached_value(:instance_followings),
last_public_event_published: last_public_event_published,
last_group_created: last_group_created
}}
end

View File

@@ -70,11 +70,19 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
end
object :dashboard do
field(:last_public_event_published, :event, description: "Last public event publish")
field(:last_public_event_published, :event, description: "Last public event published")
field(:last_group_created, :group, description: "Last public group created")
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_reports, :integer, description: "The number of current opened reports")
field(:number_of_followers, :integer, description: "The number of instance followers")
field(:number_of_followings, :integer, description: "The number of instance followings")
field(:number_of_confirmed_participations_to_local_events, :integer,
description: "The number of total confirmed participations to local events"
)
end
object :admin_settings do

View File

@@ -283,16 +283,24 @@ defmodule Mobilizon.Discussions do
end
@doc """
Counts local comments.
Counts local comments under events
"""
@spec count_local_comments :: integer
def count_local_comments, do: Repo.one(count_local_comments_query())
@spec count_local_comments_under_events :: integer
def count_local_comments_under_events do
count_local_comments_query()
|> filter_comments_under_events()
|> Repo.one()
end
@doc """
Counts all comments.
"""
@spec count_comments :: integer
def count_comments, do: Repo.one(count_comments_query())
@spec count_comments_under_events :: integer
def count_comments_under_events do
count_comments_query()
|> filter_comments_under_events()
|> Repo.one()
end
def get_discussion(discussion_id) do
Discussion
@@ -423,11 +431,8 @@ defmodule Mobilizon.Discussions do
@spec count_local_comments_query :: Ecto.Query.t()
defp count_local_comments_query do
from(
c in Comment,
select: count(c.id),
where: c.local == ^true and c.visibility in ^@public_visibility
)
count_comments_query()
|> where([c], local: true)
end
@spec count_comments_query :: Ecto.Query.t()
@@ -439,6 +444,10 @@ defmodule Mobilizon.Discussions do
)
end
defp filter_comments_under_events(query) do
where(query, [c], is_nil(c.discussion_id) and not is_nil(c.event_id))
end
@spec preload_for_comment(Ecto.Query.t()) :: Ecto.Query.t()
defp preload_for_comment(query), do: preload(query, ^@comment_preloads)
end

View File

@@ -798,6 +798,15 @@ defmodule Mobilizon.Events do
@moderator_roles [:moderator, :administrator, :creator]
@doc """
Returns the number of participations for all local events
"""
@spec count_confirmed_participants_for_local_events :: integer()
def count_confirmed_participants_for_local_events do
count_confirmed_participants_for_local_events_query()
|> Repo.one()
end
@doc """
Returns the list of participants for an event.
Default behaviour is to not return :not_approved or :not_confirmed participants
@@ -1548,6 +1557,14 @@ defmodule Mobilizon.Events do
from(s in Session, where: s.track_id == ^track_id)
end
@spec count_confirmed_participants_for_local_events_query :: Ecto.Query.t()
defp count_confirmed_participants_for_local_events_query do
Participant
|> join(:inner, [p], e in Event, on: p.event_id == e.id)
|> where([p, e], e.local and p.role not in [^:not_approved, ^:not_confirmed, ^:rejected])
|> select([p], count(p.id))
end
@spec list_participants_for_event_query(String.t()) :: Ecto.Query.t()
defp list_participants_for_event_query(event_id) do
from(

View File

@@ -26,8 +26,12 @@ defmodule Mobilizon.Service.Statistics do
Events.count_local_events()
end
defp create_cache(:confirmed_participations_to_local_events) do
Events.count_confirmed_participants_for_local_events()
end
defp create_cache(:local_comments) do
Discussions.count_local_comments()
Discussions.count_local_comments_under_events()
end
defp create_cache(:local_groups) do
@@ -39,7 +43,7 @@ defmodule Mobilizon.Service.Statistics do
end
defp create_cache(:federation_comments) do
Discussions.count_comments()
Discussions.count_comments_under_events()
end
defp create_cache(:federation_groups) do