From cd618bd8becc9834eb2d2ba83ccf7c2ec965eb59 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 26 Nov 2022 14:57:59 +0100 Subject: [PATCH] PubSubHub Plugin: make 1 external call per request (#1877) On bulk operations, this plugin heavily impacts performances because it make 1 external request per link saved. Add a simple limit to only make one call per request. --- plugins/pubsubhubbub/pubsubhubbub.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php index 299b84fb..f24f601d 100644 --- a/plugins/pubsubhubbub/pubsubhubbub.php +++ b/plugins/pubsubhubbub/pubsubhubbub.php @@ -48,6 +48,8 @@ function hook_pubsubhubbub_render_feed($data, $conf) return $data; } +$published = false; + /** * Save link hook. * Publish to the hub when a link is saved. @@ -59,6 +61,11 @@ function hook_pubsubhubbub_render_feed($data, $conf) */ function hook_pubsubhubbub_save_link($data, $conf) { + global $published; + if ($published) { + return $data; + } + $feeds = [ index_url($_SERVER) . 'feed/atom', index_url($_SERVER) . 'feed/rss', @@ -68,6 +75,7 @@ function hook_pubsubhubbub_save_link($data, $conf) try { $p = new Publisher($conf->get('plugins.PUBSUBHUB_URL')); $p->publish_update($feeds, $httpPost); + $published = true; } catch (Exception $e) { error_log(sprintf(t('Could not publish to PubSubHubbub: %s'), $e->getMessage())); }