Use update_and_set cache.
This commit is contained in:
parent
e3629af4da
commit
dfaddeb765
|
@ -128,9 +128,8 @@ def handle_incoming(%{"type" => "Update", "object" => %{"type" => "Person"} = ob
|
||||||
|
|
||||||
actor
|
actor
|
||||||
|> User.upgrade_changeset(update_data)
|
|> 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})
|
ActivityPub.update(%{local: false, to: data["to"] || [], cc: data["cc"] || [], object: object, actor: actor_id})
|
||||||
else
|
else
|
||||||
e ->
|
e ->
|
||||||
|
|
|
@ -207,7 +207,7 @@ def register(conn, params) do
|
||||||
def update_avatar(%{assigns: %{user: user}} = conn, params) do
|
def update_avatar(%{assigns: %{user: user}} = conn, params) do
|
||||||
{:ok, object} = ActivityPub.upload(params)
|
{:ok, object} = ActivityPub.upload(params)
|
||||||
change = Changeset.change(user, %{avatar: object.data})
|
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})
|
render(conn, UserView, "show.json", %{user: user, for: user})
|
||||||
end
|
end
|
||||||
|
@ -216,7 +216,7 @@ def update_banner(%{assigns: %{user: user}} = conn, params) do
|
||||||
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}),
|
with {:ok, object} <- ActivityPub.upload(%{"img" => params["banner"]}),
|
||||||
new_info <- Map.put(user.info, "banner", object.data),
|
new_info <- Map.put(user.info, "banner", object.data),
|
||||||
change <- User.info_changeset(user, %{info: new_info}),
|
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
|
%{"url" => [ %{ "href" => href } | _ ]} = object.data
|
||||||
response = %{ url: href } |> Poison.encode!
|
response = %{ url: href } |> Poison.encode!
|
||||||
conn
|
conn
|
||||||
|
@ -228,7 +228,7 @@ def update_background(%{assigns: %{user: user}} = conn, params) do
|
||||||
with {:ok, object} <- ActivityPub.upload(params),
|
with {:ok, object} <- ActivityPub.upload(params),
|
||||||
new_info <- Map.put(user.info, "background", object.data),
|
new_info <- Map.put(user.info, "background", object.data),
|
||||||
change <- User.info_changeset(user, %{info: new_info}),
|
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
|
%{"url" => [ %{ "href" => href } | _ ]} = object.data
|
||||||
response = %{ url: href } |> Poison.encode!
|
response = %{ url: href } |> Poison.encode!
|
||||||
conn
|
conn
|
||||||
|
@ -255,7 +255,7 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" =>
|
||||||
mrn <- max(id, user.info["most_recent_notification"] || 0),
|
mrn <- max(id, user.info["most_recent_notification"] || 0),
|
||||||
updated_info <- Map.put(info, "most_recent_notification", mrn),
|
updated_info <- Map.put(info, "most_recent_notification", mrn),
|
||||||
changeset <- User.info_changeset(user, %{info: updated_info}),
|
changeset <- User.info_changeset(user, %{info: updated_info}),
|
||||||
{:ok, _user} <- Repo.update(changeset) do
|
{:ok, _user} <- User.update_and_set_cache(changeset) do
|
||||||
conn
|
conn
|
||||||
|> json_reply(200, Poison.encode!(mrn))
|
|> json_reply(200, Poison.encode!(mrn))
|
||||||
else
|
else
|
||||||
|
@ -305,7 +305,7 @@ def update_profile(%{assigns: %{user: user}} = conn, params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
with changeset <- User.update_changeset(user, params),
|
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})
|
render(conn, UserView, "user.json", %{user: user, for: user})
|
||||||
else
|
else
|
||||||
error ->
|
error ->
|
||||||
|
|
|
@ -60,9 +60,8 @@ def ensure_keys_present(user) do
|
||||||
else
|
else
|
||||||
{:ok, pem} = Salmon.generate_rsa_pem
|
{:ok, pem} = Salmon.generate_rsa_pem
|
||||||
info = Map.put(info, "keys", pem)
|
info = Map.put(info, "keys", pem)
|
||||||
res = Repo.update(Ecto.Changeset.change(user, info: info))
|
Ecto.Changeset.change(user, info: info)
|
||||||
User.invalidate_cache(user)
|
|> User.update_and_set_cache()
|
||||||
res
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue