Make sure active_user_count/1 counts only local users
authorEgor Kislitsyn <egor@kislitsyn.com>
Thu, 28 Jan 2021 18:23:10 +0000 (22:23 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Thu, 28 Jan 2021 18:23:10 +0000 (22:23 +0400)
lib/pleroma/user.ex
test/pleroma/user_test.exs

index 1dde653357920c3358ee1b1b239508cca576084e..06cdb42af3becb1e645cb6a0038c16b4bf1ebf82 100644 (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
index 1fab519f00f0b26ceed8de992788f552d884c00d..ae6fc4c0db5432384d0824ff2e06a6f8557e8f73 100644 (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()})