Logger::info('Fetched featured posts', ['new' => $new, 'old' => $old, 'contact' => $url]);
}
+ public static function fetchCachedActivity(string $url, int $uid): array
+ {
+ $cachekey = self::CACHEKEY_FETCH_ACTIVITY . $uid . ':' . $url;
+ $object = DI::cache()->get($cachekey);
+
+ if (!is_null($object)) {
+ Logger::debug('Fetch from cache', ['url' => $url, 'uid' => $uid]);
+ return $object;
+ }
+
+ $object = ActivityPub::fetchContent($url, $uid);
+ if (empty($object)) {
+ Logger::notice('Activity was not fetchable, aborting.', ['url' => $url, 'uid' => $uid]);
+ return [];
+ }
+
+ if (empty($object['id'])) {
+ Logger::notice('Activity has got not id, aborting. ', ['url' => $url, 'object' => $object]);
+ return [];
+ }
+ DI::cache()->set($cachekey, $object, Duration::FIVE_MINUTES);
+
+ Logger::debug('Activity was fetched successfully', ['url' => $url, 'uid' => $uid]);
+
+ return $object;
+ }
+
/**
* Fetches missing posts
*
$uid = 0;
}
- $cachekey = self::CACHEKEY_FETCH_ACTIVITY . $url;
- $object = DI::cache()->get($cachekey);
-
- if (is_null($object)) {
- $object = ActivityPub::fetchContent($url, $uid);
- if (empty($object)) {
- Logger::notice('Activity was not fetchable, aborting.', ['url' => $url, 'uid' => $uid]);
- return '';
- }
-
- if (empty($object['id'])) {
- Logger::notice('Activity has got not id, aborting. ', ['url' => $url, 'object' => $object]);
- return '';
- }
- DI::cache()->set($cachekey, $object, Duration::FIVE_MINUTES);
- } else {
- Logger::debug('Fetch from cache', ['url' => $url]);
+ $object = self::fetchCachedActivity($url, $uid);
+ if (empty($object)) {
+ return '';
}
$signer = [];
return 'as:' . $profile['type'];
}
- $data = ActivityPub::fetchContent($object_id, $uid);
+ $data = Processor::fetchCachedActivity($object_id, $uid);
if (!empty($data)) {
$object = JsonLD::compact($data);
$type = JsonLD::fetchElement($object, '@type');
if (!empty($id) && !$trust_source) {
$fetch_uid = $uid ?: self::getBestUserForActivity($activity);
- $fetched_activity = ActivityPub::fetchContent($fetch_id, $fetch_uid);
+ $fetched_activity = Processor::fetchCachedActivity($fetch_id, $fetch_uid);
if (!empty($fetched_activity)) {
$object = JsonLD::compact($fetched_activity);
// Fetch the activity on Lemmy "Announce" messages (announces of activities)
if (($type == 'as:Announce') && in_array($object_type, array_merge(self::ACTIVITY_TYPES, ['as:Delete', 'as:Undo', 'as:Update']))) {
- $data = ActivityPub::fetchContent($object_id, $fetch_uid);
+ $data = Processor::fetchCachedActivity($object_id, $fetch_uid);
if (!empty($data)) {
$type = $object_type;
$activity = JsonLD::compact($data);
$type = JsonLD::fetchElement($object, '@type');
if (!$trust_source || empty($type)) {
- $data = ActivityPub::fetchContent($object_id, $uid);
+ $data = Processor::fetchCachedActivity($object_id, $uid);
if (!empty($data)) {
$object = JsonLD::compact($data);
Logger::info('Fetched content for ' . $object_id);