aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2018-05-25 05:19:11 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2018-05-25 05:23:49 +0000
commit47dc52a75882497d00338d07a24ce978cc0f8300 (patch)
treefb063487df783eb8c1f90a50432b62ec494e4ccf /lib
parentf3a71f2986fc0787c03bec786e772353e99ae9f9 (diff)
downloadpleroma-47dc52a75882497d00338d07a24ce978cc0f8300.tar.gz
activitypub utils: optimize block and follow activity lookup
multi-field @> comparison is very expensive, so only use @> for the field where it matters this makes the query take only a few usec to execute verses many msec on a busy instance
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 831e13b7e..cb2e1e078 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -240,11 +240,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
activity in Activity,
where:
fragment(
+ "? ->> 'type' = 'Follow'",
+ activity.data
+ ),
+ where: activity.actor == ^follower_id,
+ where:
+ fragment(
"? @> ?",
activity.data,
- ^%{type: "Follow", object: followed_id}
+ ^%{object: followed_id}
),
- where: activity.actor == ^follower_id,
order_by: [desc: :id],
limit: 1
)
@@ -365,11 +370,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
activity in Activity,
where:
fragment(
+ "? ->> 'type' = 'Block'",
+ activity.data
+ ),
+ where: activity.actor == ^blocker_id,
+ where:
+ fragment(
"? @> ?",
activity.data,
- ^%{type: "Block", object: blocked_id}
+ ^%{object: blocked_id}
),
- where: activity.actor == ^blocker_id,
order_by: [desc: :id],
limit: 1
)