From dfaddeb765cdc7b5253663d7173aca52371e48bd Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 25 Feb 2018 16:34:24 +0100 Subject: [PATCH] Use update_and_set cache. --- lib/pleroma/web/activity_pub/transmogrifier.ex | 3 +-- lib/pleroma/web/twitter_api/twitter_api_controller.ex | 10 +++++----- lib/pleroma/web/web_finger/web_finger.ex | 5 ++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 0d73ddc5d..6974c39b1 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -128,9 +128,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do actor |> User.upgrade_changeset(update_data) - |> Repo.update + |> User.update_and_set_cache() - User.invalidate_cache(actor) ActivityPub.update(%{local: false, to: data["to"] || [], cc: data["cc"] || [], object: object, actor: actor_id}) else e -> diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 5284a8847..3eb4f5d63 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -207,7 +207,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def update_avatar(%{assigns: %{user: user}} = conn, params) do {:ok, object} = ActivityPub.upload(params) change = Changeset.change(user, %{avatar: object.data}) - {:ok, user} = Repo.update(change) + {:ok, user} = User.update_and_set_cache(change) render(conn, UserView, "show.json", %{user: user, for: user}) end @@ -216,7 +216,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}), new_info <- Map.put(user.info, "banner", object.data), change <- User.info_changeset(user, %{info: new_info}), - {:ok, _user} <- Repo.update(change) do + {:ok, _user} <- User.update_and_set_cache(change) do %{"url" => [ %{ "href" => href } | _ ]} = object.data response = %{ url: href } |> Poison.encode! conn @@ -228,7 +228,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do with {:ok, object} <- ActivityPub.upload(params), new_info <- Map.put(user.info, "background", object.data), change <- User.info_changeset(user, %{info: new_info}), - {:ok, _user} <- Repo.update(change) do + {:ok, _user} <- User.update_and_set_cache(change) do %{"url" => [ %{ "href" => href } | _ ]} = object.data response = %{ url: href } |> Poison.encode! conn @@ -255,7 +255,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do mrn <- max(id, user.info["most_recent_notification"] || 0), updated_info <- Map.put(info, "most_recent_notification", mrn), changeset <- User.info_changeset(user, %{info: updated_info}), - {:ok, _user} <- Repo.update(changeset) do + {:ok, _user} <- User.update_and_set_cache(changeset) do conn |> json_reply(200, Poison.encode!(mrn)) else @@ -305,7 +305,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end with changeset <- User.update_changeset(user, params), - {:ok, user} <- Repo.update(changeset) do + {:ok, user} <- User.update_and_set_cache(changeset) do render(conn, UserView, "user.json", %{user: user, for: user}) else error -> diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 7576ea28a..c59a7e82d 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -60,9 +60,8 @@ defmodule Pleroma.Web.WebFinger do else {:ok, pem} = Salmon.generate_rsa_pem info = Map.put(info, "keys", pem) - res = Repo.update(Ecto.Changeset.change(user, info: info)) - User.invalidate_cache(user) - res + Ecto.Changeset.change(user, info: info) + |> User.update_and_set_cache() end end