aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma')
-rw-r--r--lib/pleroma/application.ex8
-rw-r--r--lib/pleroma/object.ex20
-rw-r--r--lib/pleroma/user.ex12
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex14
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex5
-rw-r--r--lib/pleroma/web/common_api/utils.ex2
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex6
7 files changed, 32 insertions, 35 deletions
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index e1e3bcd63..a89728471 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -5,6 +5,7 @@ defmodule Pleroma.Application do
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec
+ import Cachex.Spec
# Define workers and child supervisors to be supervised
children =
@@ -28,8 +29,11 @@ defmodule Pleroma.Application do
[
:idempotency_cache,
[
- default_ttl: :timer.seconds(6 * 60 * 60),
- ttl_interval: :timer.seconds(60),
+ expiration:
+ expiration(
+ default: :timer.seconds(6 * 60 * 60),
+ interval: :timer.seconds(60)
+ ),
limit: 2500
]
],
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex
index 558e151b0..ff2af4a6f 100644
--- a/lib/pleroma/object.ex
+++ b/lib/pleroma/object.ex
@@ -33,19 +33,15 @@ defmodule Pleroma.Object do
else
key = "object:#{ap_id}"
- Cachex.get!(
- :user_cache,
- key,
- fallback: fn _ ->
- object = get_by_ap_id(ap_id)
-
- if object do
- {:commit, object}
- else
- {:ignore, object}
- end
+ Cachex.fetch!(:user_cache, key, fn _ ->
+ object = get_by_ap_id(ap_id)
+
+ if object do
+ {:commit, object}
+ else
+ {:ignore, object}
end
- )
+ end)
end
end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 6a8129ac8..690cc7cf3 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -223,9 +223,9 @@ defmodule Pleroma.User do
def update_and_set_cache(changeset) do
with {:ok, user} <- Repo.update(changeset) do
- Cachex.set(:user_cache, "ap_id:#{user.ap_id}", user)
- Cachex.set(:user_cache, "nickname:#{user.nickname}", user)
- Cachex.set(:user_cache, "user_info:#{user.id}", user_info(user))
+ Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)
+ Cachex.put(:user_cache, "nickname:#{user.nickname}", user)
+ Cachex.put(:user_cache, "user_info:#{user.id}", user_info(user))
{:ok, user}
else
e -> e
@@ -239,12 +239,12 @@ defmodule Pleroma.User do
def get_cached_by_ap_id(ap_id) do
key = "ap_id:#{ap_id}"
- Cachex.get!(:user_cache, key, fallback: fn _ -> get_by_ap_id(ap_id) end)
+ Cachex.fetch!(:user_cache, key, fn _ -> get_by_ap_id(ap_id) end)
end
def get_cached_by_nickname(nickname) do
key = "nickname:#{nickname}"
- Cachex.get!(:user_cache, key, fallback: fn _ -> get_or_fetch_by_nickname(nickname) end)
+ Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end)
end
def get_by_nickname(nickname) do
@@ -260,7 +260,7 @@ defmodule Pleroma.User do
def get_cached_user_info(user) do
key = "user_info:#{user.id}"
- Cachex.get!(:user_cache, key, fallback: fn _ -> user_info(user) end)
+ Cachex.fetch!(:user_cache, key, fn _ -> user_info(user) end)
end
def fetch_by_nickname(nickname) do
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index a31452a63..7d6fd8632 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -229,7 +229,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
"object" => %{"type" => "Announce", "object" => object_id},
"actor" => actor,
"id" => id
- } = data
+ } = _data
) do
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
{:ok, object} <-
@@ -237,7 +237,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
{:ok, activity, _, _} <- ActivityPub.unannounce(actor, object, id, false) do
{:ok, activity}
else
- e -> :error
+ _e -> :error
end
end
@@ -247,7 +247,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
"object" => %{"type" => "Like", "object" => object_id},
"actor" => actor,
"id" => id
- } = data
+ } = _data
) do
with %User{} = actor <- User.get_or_fetch_by_ap_id(actor),
{:ok, object} <-
@@ -255,7 +255,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
{:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
{:ok, activity}
else
- e -> :error
+ _e -> :error
end
end
@@ -516,10 +516,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def maybe_fix_user_url(data) do
if is_map(data["url"]) do
- data = Map.put(data, "url", data["url"]["href"])
+ Map.put(data, "url", data["url"]["href"])
+ else
+ data
end
-
- data
end
def maybe_fix_user_object(data) do
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 937f032c3..a3feca480 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -242,8 +242,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do
fragment(
"? @> ?",
activity.data,
- ^%{type: "Follow", actor: follower_id, object: followed_id}
+ ^%{type: "Follow", object: followed_id}
),
+ where: activity.actor == ^follower_id,
order_by: [desc: :id],
limit: 1
)
@@ -260,7 +261,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
query =
from(
activity in Activity,
- where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
+ where: activity.actor == ^actor,
# this is to use the index
where:
fragment(
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 4ac45b592..9c9951371 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -133,7 +133,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
"context" => context,
"attachment" => attachments,
"actor" => actor,
- "tag" => tags |> Enum.map(fn {_, tag} -> tag end)
+ "tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
}
if inReplyTo do
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 85f9c5b7b..e6365620e 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -275,11 +275,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
{:ok, activity} =
- Cachex.get!(
- :idempotency_cache,
- idempotency_key,
- fallback: fn _ -> CommonAPI.post(user, params) end
- )
+ Cachex.fetch!(:idempotency_cache, idempotency_key, fn _ -> CommonAPI.post(user, params) end)
render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity})
end