From 039846d46513b22a4b8618b9ed589b5b503df236 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 16 Dec 2019 11:47:31 +0100 Subject: [PATCH] Clear AP cache when content is updated or deleted Signed-off-by: Thomas Citharel --- lib/mobilizon/actors/actors.ex | 1 + lib/service/activity_pub/activity_pub.ex | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 05fc1c3d..a9271085 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -249,6 +249,7 @@ defmodule Mobilizon.Actors do case transaction do {:ok, %{actor: %Actor{} = actor}} -> + {:ok, true} = Cachex.del(:activity_pub, "actor_#{actor.preferred_username}") {:ok, actor} {:error, remove, error, _} when remove in [:remove_banner, :remove_avatar] -> diff --git a/lib/service/activity_pub/activity_pub.ex b/lib/service/activity_pub/activity_pub.ex index 4c612c80..298ba869 100644 --- a/lib/service/activity_pub/activity_pub.ex +++ b/lib/service/activity_pub/activity_pub.ex @@ -328,6 +328,7 @@ defmodule Mobilizon.Service.ActivityPub do with audience <- Audience.calculate_to_and_cc_from_mentions(event), {:ok, %Event{} = event} <- Events.delete_event(event), + {:ok, true} <- Cachex.del(:activity_pub, "event_#{event.uuid}"), {:ok, %Tombstone{} = _tombstone} <- Tombstone.create_tombstone(%{uri: event.url, actor_id: actor.id}), Share.delete_all_by_uri(event.url), @@ -350,6 +351,7 @@ defmodule Mobilizon.Service.ActivityPub do with audience <- Audience.calculate_to_and_cc_from_mentions(comment), {:ok, %Comment{} = comment} <- Events.delete_comment(comment), + {:ok, true} <- Cachex.del(:activity_pub, "comment_#{comment.uuid}"), {:ok, %Tombstone{} = _tombstone} <- Tombstone.create_tombstone(%{uri: comment.url, actor_id: actor.id}), Share.delete_all_by_uri(comment.url), @@ -730,6 +732,7 @@ defmodule Mobilizon.Service.ActivityPub do ) do with args <- prepare_args_for_event(args), {:ok, %Event{} = new_event} <- Events.update_event(old_event, args), + {:ok, true} <- Cachex.del(:activity_pub, "event_#{new_event.uuid}"), event_as_data <- Convertible.model_to_as(new_event), audience <- Audience.calculate_to_and_cc_from_mentions(new_event), @@ -748,6 +751,7 @@ defmodule Mobilizon.Service.ActivityPub do defp update_actor(%Actor{} = old_actor, args, additional) do with {:ok, %Actor{} = new_actor} <- Actors.update_actor(old_actor, args), actor_as_data <- Convertible.model_to_as(new_actor), + {:ok, true} <- Cachex.del(:activity_pub, "actor_#{new_actor.preferred_username}"), audience <- Audience.calculate_to_and_cc_from_mentions(new_actor), additional <- Map.merge(additional, %{"actor" => old_actor.url}),