mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-20 00:20:59 +00:00
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
This commit is contained in:
parent
f3a71f2986
commit
47dc52a758
1 changed files with 16 additions and 6 deletions
|
@ -240,11 +240,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
activity in Activity,
|
||||
where:
|
||||
fragment(
|
||||
"? @> ?",
|
||||
activity.data,
|
||||
^%{type: "Follow", object: followed_id}
|
||||
"? ->> 'type' = 'Follow'",
|
||||
activity.data
|
||||
),
|
||||
where: activity.actor == ^follower_id,
|
||||
where:
|
||||
fragment(
|
||||
"? @> ?",
|
||||
activity.data,
|
||||
^%{object: followed_id}
|
||||
),
|
||||
order_by: [desc: :id],
|
||||
limit: 1
|
||||
)
|
||||
|
@ -365,11 +370,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
activity in Activity,
|
||||
where:
|
||||
fragment(
|
||||
"? @> ?",
|
||||
activity.data,
|
||||
^%{type: "Block", object: blocked_id}
|
||||
"? ->> 'type' = 'Block'",
|
||||
activity.data
|
||||
),
|
||||
where: activity.actor == ^blocker_id,
|
||||
where:
|
||||
fragment(
|
||||
"? @> ?",
|
||||
activity.data,
|
||||
^%{object: blocked_id}
|
||||
),
|
||||
order_by: [desc: :id],
|
||||
limit: 1
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue