Add local groups as statistics

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-09-30 10:42:19 +02:00
parent 2dccd5eccd
commit a600720062
9 changed files with 79 additions and 5 deletions

View File

@@ -288,6 +288,12 @@ defmodule Mobilizon.Discussions do
@spec count_local_comments :: integer
def count_local_comments, do: Repo.one(count_local_comments_query())
@doc """
Counts all comments.
"""
@spec count_comments :: integer
def count_comments, do: Repo.one(count_comments_query())
def get_discussion(discussion_id) do
Discussion
|> Repo.get(discussion_id)
@@ -424,6 +430,15 @@ defmodule Mobilizon.Discussions do
)
end
@spec count_comments_query :: Ecto.Query.t()
defp count_comments_query do
from(
c in Comment,
select: count(c.id),
where: c.visibility in ^@public_visibility
)
end
@spec preload_for_comment(Ecto.Query.t()) :: Ecto.Query.t()
defp preload_for_comment(query), do: preload(query, ^@comment_preloads)
end