aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/websub/websub.ex
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-01-24 19:15:23 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-01-24 19:15:23 +0300
commit3e9399ec0b498c0c9783ccb0fea9f682c8b9d0ca (patch)
tree9fe891c45283c89fe11e4a53d49a4c91c8fdf52c /lib/pleroma/web/websub/websub.ex
parent8654a591f08c7d8d5d61f075906f0c6907e877bb (diff)
downloadpleroma-3e9399ec0b498c0c9783ccb0fea9f682c8b9d0ca.tar.gz
[#534] Optimized bulk publish ops to filter on reachability early. `Instance` refactoring.
Diffstat (limited to 'lib/pleroma/web/websub/websub.ex')
-rw-r--r--lib/pleroma/web/websub/websub.ex18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex
index ac8903913..bb4442591 100644
--- a/lib/pleroma/web/websub/websub.ex
+++ b/lib/pleroma/web/websub/websub.ex
@@ -54,7 +54,12 @@ defmodule Pleroma.Web.Websub do
]
def publish(topic, user, %{data: %{"type" => type}} = activity)
when type in @supported_activities do
- # TODO: Only send to still valid subscriptions.
+ response =
+ user
+ |> FeedRepresenter.to_simple_form([activity], [user])
+ |> :xmerl.export_simple(:xmerl_xml)
+ |> to_string
+
query =
from(
sub in WebsubServerSubscription,
@@ -64,13 +69,12 @@ defmodule Pleroma.Web.Websub do
subscriptions = Repo.all(query)
- Enum.each(subscriptions, fn sub ->
- response =
- user
- |> FeedRepresenter.to_simple_form([activity], [user])
- |> :xmerl.export_simple(:xmerl_xml)
- |> to_string
+ callbacks = Enum.map(subscriptions, & &1.callback)
+ reachable_callbacks = Instances.filter_reachable(callbacks)
+ subscriptions
+ |> Enum.filter(&(&1.callback in reachable_callbacks))
+ |> Enum.each(fn sub ->
data = %{
xml: response,
topic: topic,