Merge branch 'refactor/object-cache-deletion' into 'develop'
object cache deletion refactoring, part 2 See merge request pleroma/pleroma!409
This commit is contained in:
commit
27a06bd440
@ -7,7 +7,7 @@ defmodule Mix.Tasks.RmUser do
|
|||||||
Mix.Task.run("app.start")
|
Mix.Task.run("app.start")
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||||
User.delete(user)
|
{:ok, _} = User.delete(user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,14 +16,30 @@ defmodule Pleroma.Application do
|
|||||||
supervisor(Pleroma.Web.Endpoint, []),
|
supervisor(Pleroma.Web.Endpoint, []),
|
||||||
# Start your own worker by calling: Pleroma.Worker.start_link(arg1, arg2, arg3)
|
# Start your own worker by calling: Pleroma.Worker.start_link(arg1, arg2, arg3)
|
||||||
# worker(Pleroma.Worker, [arg1, arg2, arg3]),
|
# worker(Pleroma.Worker, [arg1, arg2, arg3]),
|
||||||
worker(Cachex, [
|
worker(
|
||||||
:user_cache,
|
Cachex,
|
||||||
[
|
[
|
||||||
default_ttl: 25000,
|
:user_cache,
|
||||||
ttl_interval: 1000,
|
[
|
||||||
limit: 2500
|
default_ttl: 25000,
|
||||||
]
|
ttl_interval: 1000,
|
||||||
]),
|
limit: 2500
|
||||||
|
]
|
||||||
|
],
|
||||||
|
id: :cachex_user
|
||||||
|
),
|
||||||
|
worker(
|
||||||
|
Cachex,
|
||||||
|
[
|
||||||
|
:object_cache,
|
||||||
|
[
|
||||||
|
default_ttl: 25000,
|
||||||
|
ttl_interval: 1000,
|
||||||
|
limit: 2500
|
||||||
|
]
|
||||||
|
],
|
||||||
|
id: :cachex_object
|
||||||
|
),
|
||||||
worker(
|
worker(
|
||||||
Cachex,
|
Cachex,
|
||||||
[
|
[
|
||||||
|
@ -37,7 +37,7 @@ defmodule Pleroma.Object do
|
|||||||
else
|
else
|
||||||
key = "object:#{ap_id}"
|
key = "object:#{ap_id}"
|
||||||
|
|
||||||
Cachex.fetch!(:user_cache, key, fn _ ->
|
Cachex.fetch!(:object_cache, key, fn _ ->
|
||||||
object = get_by_ap_id(ap_id)
|
object = get_by_ap_id(ap_id)
|
||||||
|
|
||||||
if object do
|
if object do
|
||||||
@ -56,8 +56,8 @@ defmodule Pleroma.Object do
|
|||||||
def delete(%Object{data: %{"id" => id}} = object) do
|
def delete(%Object{data: %{"id" => id}} = object) do
|
||||||
with Repo.delete(object),
|
with Repo.delete(object),
|
||||||
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
|
||||||
{:ok, true} <- Cachex.del(:user_cache, "object:#{id}") do
|
{:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
|
||||||
:ok
|
{:ok, object}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -295,6 +295,7 @@ defmodule Pleroma.User do
|
|||||||
def invalidate_cache(user) do
|
def invalidate_cache(user) do
|
||||||
Cachex.del(:user_cache, "ap_id:#{user.ap_id}")
|
Cachex.del(:user_cache, "ap_id:#{user.ap_id}")
|
||||||
Cachex.del(:user_cache, "nickname:#{user.nickname}")
|
Cachex.del(:user_cache, "nickname:#{user.nickname}")
|
||||||
|
Cachex.del(:user_cache, "user_info:#{user.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_cached_by_ap_id(ap_id) do
|
def get_cached_by_ap_id(ap_id) do
|
||||||
@ -656,7 +657,7 @@ defmodule Pleroma.User do
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
:ok
|
{:ok, user}
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_filter_policy(%User{info: %{"no_rich_text" => true}}) do
|
def html_filter_policy(%User{info: %{"no_rich_text" => true}}) do
|
||||||
|
@ -273,7 +273,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
"to" => [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"]
|
"to" => [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"]
|
||||||
}
|
}
|
||||||
|
|
||||||
with Object.delete(object),
|
with {:ok, _} <- Object.delete(object),
|
||||||
{:ok, activity} <- insert(data, local),
|
{:ok, activity} <- insert(data, local),
|
||||||
:ok <- maybe_federate(activity),
|
:ok <- maybe_federate(activity),
|
||||||
{:ok, _actor} <- User.decrease_note_count(user) do
|
{:ok, _actor} <- User.decrease_note_count(user) do
|
||||||
|
@ -42,7 +42,7 @@ defmodule Pleroma.ObjectTest do
|
|||||||
|
|
||||||
Object.delete(cached_object)
|
Object.delete(cached_object)
|
||||||
|
|
||||||
{:ok, nil} = Cachex.get(:user_cache, "object:#{object.data["id"]}")
|
{:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
|
||||||
|
|
||||||
cached_object = Object.get_cached_by_ap_id(object.data["id"])
|
cached_object = Object.get_cached_by_ap_id(object.data["id"])
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ defmodule Pleroma.UserTest do
|
|||||||
{:ok, _, _} = CommonAPI.favorite(activity.id, follower)
|
{:ok, _, _} = CommonAPI.favorite(activity.id, follower)
|
||||||
{:ok, _, _} = CommonAPI.repeat(activity.id, follower)
|
{:ok, _, _} = CommonAPI.repeat(activity.id, follower)
|
||||||
|
|
||||||
:ok = User.delete(user)
|
{:ok, _} = User.delete(user)
|
||||||
|
|
||||||
followed = Repo.get(User, followed.id)
|
followed = Repo.get(User, followed.id)
|
||||||
follower = Repo.get(User, follower.id)
|
follower = Repo.get(User, follower.id)
|
||||||
@ -551,4 +551,31 @@ defmodule Pleroma.UserTest do
|
|||||||
assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
|
assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "caching" do
|
||||||
|
test "invalidate_cache works" do
|
||||||
|
user = insert(:user)
|
||||||
|
user_info = User.get_cached_user_info(user)
|
||||||
|
|
||||||
|
User.invalidate_cache(user)
|
||||||
|
|
||||||
|
{:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||||
|
{:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}")
|
||||||
|
{:ok, nil} = Cachex.get(:user_cache, "user_info:#{user.id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "User.delete() plugs any possible zombie objects" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, _} = User.delete(user)
|
||||||
|
|
||||||
|
{:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||||
|
|
||||||
|
assert cached_user != user
|
||||||
|
|
||||||
|
{:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}")
|
||||||
|
|
||||||
|
assert cached_user != user
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user