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 @@ defmodule Pleroma.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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.UserTest 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()})