From: Egor Kislitsyn Date: Thu, 28 Jan 2021 18:23:10 +0000 (+0400) Subject: Make sure active_user_count/1 counts only local users X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=a51d903e0c8c87247df6b3cdecc476269edf58ce;p=akkoma Make sure active_user_count/1 counts only local users --- diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1dde65335..06cdb42af 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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 diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 1fab519f0..ae6fc4c0d 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -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()})