Remove follow_request_count as it's not needed for FE anymore.

MastoFE uses `GET /api/v1/follow_requests` and PleromaFE uses
`GET /api/pleroma/friend_requests` which they query on the initial page
load.
This commit is contained in:
eugenijm 2019-03-03 18:39:37 +03:00
parent 9b63fda9c7
commit d5418e9ff7
6 changed files with 4 additions and 53 deletions

View file

@ -621,32 +621,6 @@ def get_follow_requests_query(%User{} = user) do
)
end
def update_follow_request_count(%User{} = user) do
subquery =
user
|> User.get_follow_requests_query()
|> select([a], %{count: count(a.id)})
User
|> where(id: ^user.id)
|> join(:inner, [u], s in subquery(subquery))
|> update([u, s],
set: [
info:
fragment(
"jsonb_set(?, '{follow_request_count}', ?::varchar::jsonb, true)",
u.info,
s.count
)
]
)
|> Repo.update_all([], returning: true)
|> case do
{1, [user]} -> {:ok, user}
_ -> {:error, user}
end
end
def get_follow_requests(%User{} = user) do
q = get_follow_requests_query(user)
reqs = Repo.all(q)

View file

@ -12,7 +12,6 @@ defmodule Pleroma.User.Info do
field(:source_data, :map, default: %{})
field(:note_count, :integer, default: 0)
field(:follower_count, :integer, default: 0)
field(:follow_request_count, :integer, default: 0)
field(:locked, :boolean, default: false)
field(:confirmation_pending, :boolean, default: false)
field(:confirmation_token, :string, default: nil)

View file

@ -175,8 +175,7 @@ def accept(%{to: to, actor: actor, object: object} = params) do
with data <- %{"to" => to, "type" => "Accept", "actor" => actor.ap_id, "object" => object},
{:ok, activity} <- insert(data, local),
:ok <- maybe_federate(activity),
_ <- User.update_follow_request_count(actor) do
:ok <- maybe_federate(activity) do
{:ok, activity}
end
end
@ -187,8 +186,7 @@ def reject(%{to: to, actor: actor, object: object} = params) do
with data <- %{"to" => to, "type" => "Reject", "actor" => actor.ap_id, "object" => object},
{:ok, activity} <- insert(data, local),
:ok <- maybe_federate(activity),
_ <- User.update_follow_request_count(actor) do
:ok <- maybe_federate(activity) do
{:ok, activity}
end
end
@ -286,8 +284,7 @@ def unannounce(
def follow(follower, followed, activity_id \\ nil, local \\ true) do
with data <- make_follow_data(follower, followed, activity_id),
{:ok, activity} <- insert(data, local),
:ok <- maybe_federate(activity),
_ <- User.update_follow_request_count(followed) do
:ok <- maybe_federate(activity) do
{:ok, activity}
end
end
@ -297,8 +294,7 @@ def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
{:ok, follow_activity} <- update_follow_state(follow_activity, "cancelled"),
unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
{:ok, activity} <- insert(unfollow_data, local),
:ok <- maybe_federate(activity),
_ <- User.update_follow_request_count(followed) do
:ok <- maybe_federate(activity) do
{:ok, activity}
end
end

View file

@ -133,7 +133,6 @@ defp do_render("user.json", %{user: user = %User{}} = assigns) do
"tags" => user.tags
}
|> maybe_with_activation_status(user, for_user)
|> maybe_with_follow_request_count(user, for_user)
}
data =
@ -155,14 +154,6 @@ defp maybe_with_activation_status(data, user, %User{info: %{is_admin: true}}) do
defp maybe_with_activation_status(data, _, _), do: data
defp maybe_with_follow_request_count(data, %User{id: id, info: %{locked: true}} = user, %User{
id: id
}) do
Map.put(data, "follow_request_count", user.info.follow_request_count)
end
defp maybe_with_follow_request_count(data, _, _), do: data
defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do
Map.merge(data, %{"role" => role(user), "show_role" => user.info.show_role})
end

View file

@ -946,7 +946,6 @@ test "/api/v1/follow_requests/:id/authorize works" do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
assert user.info.follow_request_count == 1
conn =
build_conn()
@ -960,7 +959,6 @@ test "/api/v1/follow_requests/:id/authorize works" do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == true
assert user.info.follow_request_count == 0
end
test "verify_credentials", %{conn: conn} do
@ -982,7 +980,6 @@ test "/api/v1/follow_requests/:id/reject works" do
{:ok, _activity} = ActivityPub.follow(other_user, user)
user = Repo.get(User, user.id)
assert user.info.follow_request_count == 1
conn =
build_conn()
@ -996,7 +993,6 @@ test "/api/v1/follow_requests/:id/reject works" do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
assert user.info.follow_request_count == 0
end
end

View file

@ -690,7 +690,6 @@ test "for restricted account", %{conn: conn, user: current_user} do
followed = Repo.get(User, followed.id)
refute User.ap_followers(followed) in current_user.following
assert followed.info.follow_request_count == 1
assert json_response(conn, 200) ==
UserView.render("show.json", %{user: followed, for: current_user})
@ -1757,7 +1756,6 @@ test "it approves a friend request" do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
assert user.info.follow_request_count == 1
conn =
build_conn()
@ -1769,7 +1767,6 @@ test "it approves a friend request" do
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == true
assert user.info.follow_request_count == 0
end
end
@ -1784,7 +1781,6 @@ test "it denies a friend request" do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
assert user.info.follow_request_count == 1
conn =
build_conn()
@ -1796,7 +1792,6 @@ test "it denies a friend request" do
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == false
assert user.info.follow_request_count == 0
end
end