1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-27 02:10:27 +00:00
mobilizon/lib/service/statistics/statistics.ex
Thomas Citharel 4144e9ffd0
Introduce group basic federation, event new page and notifications
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2020-06-03 16:01:26 +02:00

31 lines
736 B
Elixir

defmodule Mobilizon.Service.Statistics do
@moduledoc """
A module that provides cached statistics
"""
alias Mobilizon.{Conversations, Events, Users}
def get_cached_value(key) do
case Cachex.fetch(:statistics, key, fn key ->
case create_cache(key) do
value when not is_nil(value) -> {:commit, value}
err -> {:ignore, err}
end
end) do
{status, value} when status in [:ok, :commit] -> value
_err -> nil
end
end
defp create_cache(:local_users) do
Users.count_users()
end
defp create_cache(:local_events) do
Events.count_local_events()
end
defp create_cache(:local_comments) do
Conversations.count_local_comments()
end
end