Use User.get_cached_by*
authoreugenijm <eugenijm@protonmail.com>
Mon, 15 Apr 2019 09:37:49 +0000 (12:37 +0300)
committereugenijm <eugenijm@protonmail.com>
Mon, 15 Apr 2019 09:37:49 +0000 (12:37 +0300)
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index c051d0d7ba64f7114b8fcc1a74b978935fca128a..63fadce3811ceea8a681860888d49ad8f8f4cb8d 100644 (file)
@@ -815,7 +815,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   end
 
   def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
-    with {_, %User{} = followed} <- {:followed, User.get_by_id(id)},
+    with {_, %User{} = followed} <- {:followed, User.get_cached_by_id(id)},
          {_, true} <- {:followed, follower.id != followed.id},
          false <- User.following?(follower, followed),
          {:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
@@ -847,7 +847,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   end
 
   def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
-    with {_, %User{} = followed} <- {:followed, User.get_by_nickname(uri)},
+    with {_, %User{} = followed} <- {:followed, User.get_cached_by_nickname(uri)},
          {_, true} <- {:followed, follower.id != followed.id},
          {:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
       conn
@@ -865,7 +865,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
   end
 
   def unfollow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
-    with {_, %User{} = followed} <- {:followed, User.get_by_id(id)},
+    with {_, %User{} = followed} <- {:followed, User.get_cached_by_id(id)},
          {_, true} <- {:followed, follower.id != followed.id},
          {:ok, follower} <- CommonAPI.unfollow(follower, followed) do
       conn
index ad1828ee7d6926d616510e385f443722ceadee1a..e2a96fbfad53b6d7947e627c1c646076753578c6 100644 (file)
@@ -1599,12 +1599,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
     assert %{"error" => "Record not found"} = json_response(conn_res, 404)
 
     # self unfollow
-    user = User.get_by_id(user.id)
+    user = User.get_cached_by_id(user.id)
     conn_res = post(conn, "/api/v1/accounts/#{user.id}/unfollow")
     assert %{"error" => "Record not found"} = json_response(conn_res, 404)
 
     # self follow via uri
-    user = User.get_by_id(user.id)
+    user = User.get_cached_by_id(user.id)
     conn_res = post(conn, "/api/v1/follows", %{"uri" => user.nickname})
     assert %{"error" => "Record not found"} = json_response(conn_res, 404)