Make sure active_user_count/1 counts only local users

This commit is contained in:
Egor Kislitsyn 2021-01-28 22:23:10 +04:00
parent 13a2ae8ce0
commit a51d903e0c
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805
2 changed files with 3 additions and 1 deletions

View File

@ -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

View File

@ -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()})