forked from AkkomaGang/akkoma
Use update_and_set cache.
This commit is contained in:
parent
e3629af4da
commit
dfaddeb765
3 changed files with 8 additions and 10 deletions
|
@ -128,9 +128,8 @@ def handle_incoming(%{"type" => "Update", "object" => %{"type" => "Person"} = ob
|
|||
|
||||
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 ->
|
||||
|
|
|
@ -207,7 +207,7 @@ def register(conn, params) 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 @@ def update_banner(%{assigns: %{user: user}} = conn, params) 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 @@ def update_background(%{assigns: %{user: user}} = conn, params) 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 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" =>
|
|||
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 @@ def update_profile(%{assigns: %{user: user}} = conn, params) 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 ->
|
||||
|
|
|
@ -60,9 +60,8 @@ def ensure_keys_present(user) 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
|
||||
|
||||
|
|
Loading…
Reference in a new issue