Add active user count
This commit is contained in:
parent
7f07871639
commit
793fc77b16
7 changed files with 60 additions and 1 deletions
|
|
@ -146,6 +146,7 @@ defmodule Pleroma.User do
|
|||
field(:inbox, :string)
|
||||
field(:shared_inbox, :string)
|
||||
field(:accepts_chat_messages, :boolean, default: nil)
|
||||
field(:last_active_at, :naive_datetime)
|
||||
|
||||
embeds_one(
|
||||
:notification_settings,
|
||||
|
|
@ -2444,4 +2445,18 @@ defmodule Pleroma.User do
|
|||
def get_host(%User{ap_id: ap_id} = _user) do
|
||||
URI.parse(ap_id).host
|
||||
end
|
||||
|
||||
def update_last_active_at(user) do
|
||||
user
|
||||
|> cast(%{last_active_at: NaiveDateTime.utc_now()}, [:last_active_at])
|
||||
|> update_and_set_cache()
|
||||
end
|
||||
|
||||
def active_user_count(weeks \\ 4) do
|
||||
active_after = Timex.shift(NaiveDateTime.utc_now(), weeks: -weeks)
|
||||
|
||||
__MODULE__
|
||||
|> where([u], u.last_active_at >= ^active_after)
|
||||
|> Repo.aggregate(:count)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue