Make sure active_user_count/1 counts only local users
This commit is contained in:
parent
13a2ae8ce0
commit
a51d903e0c
|
@ -2446,7 +2446,7 @@ def get_host(%User{ap_id: ap_id} = _user) do
|
|||
URI.parse(ap_id).host
|
||||
end
|
||||
|
||||
def update_last_active_at(user) do
|
||||
def update_last_active_at(%__MODULE__{local: true} = user) do
|
||||
user
|
||||
|> cast(%{last_active_at: NaiveDateTime.utc_now()}, [:last_active_at])
|
||||
|> update_and_set_cache()
|
||||
|
@ -2457,6 +2457,7 @@ def active_user_count(weeks \\ 4) do
|
|||
|
||||
__MODULE__
|
||||
|> where([u], u.last_active_at >= ^active_after)
|
||||
|> where([u], u.local == true)
|
||||
|> Repo.aggregate(:count)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2278,6 +2278,7 @@ test "update_last_active_at/1" do
|
|||
|
||||
test "active_user_count/1" do
|
||||
insert(:user)
|
||||
insert(:user, %{local: false})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -5)})
|
||||
insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -3)})
|
||||
insert(:user, %{last_active_at: NaiveDateTime.utc_now()})
|
||||
|
|
Loading…
Reference in a new issue