use Friendica\Core\Config;
use Friendica\Object\Image;
use Friendica\Protocol\ActivityPub;
+use Friendica\Core\Cache;
/**
* @brief ActivityPub Transmitter Protocol class
return $type;
}
+ /**
+ * @brief Creates the activity or fetches it from the cache
+ *
+ * @param integer $item_id
+ *
+ * @return array with the activity
+ */
+ public static function createCachedActivityFromItem($item_id)
+ {
+ $cachekey = "APDelivery:createActivity:".$item_id;
+ $data = Cache::get($cachekey);
+ if (!is_null($data)) {
+ return $data;
+ }
+
+ $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
+
+ Cache::set($cachekey, $data, CACHE_QUARTER_HOUR);
+ return $data;
+ }
+
/**
* @brief Creates an activity array for a given item id
*
class APDelivery extends BaseObject
{
+ /**
+ * @brief Delivers ActivityPub messages
+ *
+ * @param string $cmd
+ * @param integer $item_id
+ * @param string $inbox
+ * @param integer $uid
+ */
public static function execute($cmd, $item_id, $inbox, $uid)
{
logger('Invoked: ' . $cmd . ': ' . $item_id . ' to ' . $inbox, LOGGER_DEBUG);
} elseif ($cmd == Delivery::PROFILEUPDATE) {
ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
} else {
- $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
+ $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
if (!empty($data)) {
HTTPSignature::transmit($data, $inbox, $uid);
}
}
-
- return;
}
}
$inboxes = array_merge($inboxes, $parent_inboxes);
}
+ // Fill the item cache
+ ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
+
foreach ($inboxes as $inbox) {
logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);