diff options
author | lambda <pleromagit@rogerbraun.net> | 2018-05-25 07:13:05 +0000 |
---|---|---|
committer | lambda <pleromagit@rogerbraun.net> | 2018-05-25 07:13:05 +0000 |
commit | caae83e6d54caaac1790a727b902e70adffd296f (patch) | |
tree | f788df8212896c2f7e1636279417531d6f4a2fa9 | |
parent | f3a71f2986fc0787c03bec786e772353e99ae9f9 (diff) | |
parent | 5f06a1a3c51fcc2b3782879ed900e13266bfd18e (diff) | |
download | pleroma-caae83e6d54caaac1790a727b902e70adffd296f.tar.gz |
Merge branch 'bugfix/follow-query-overhead' into 'develop'
activitypub utils: optimize block and follow activity lookup
See merge request pleroma/pleroma!171
-rw-r--r-- | lib/pleroma/web/activity_pub/utils.ex | 18 | ||||
-rw-r--r-- | test/web/common_api/common_api_test.exs | 2 |
2 files changed, 15 insertions, 5 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 ) diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index b597e6e0a..a5da271b3 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -1,4 +1,4 @@ -defmodule Pleroma.Web.CommonAPI.UtilsTest do +defmodule Pleroma.Web.CommonAPI.Test do use Pleroma.DataCase alias Pleroma.Web.CommonAPI |