friendship ended with social-app. php is my new best friend

do some more concurrency stuff

Changed files
+23 -28
lib
+23 -28
lib/bskyToucher.php
···
}, $body->feed)));
return $res;
-
-
/*return array_map(function($item) {
-
return $item->json();
-
}, $res);*/
}));
$body->feed = $ret;
-
/*$body->feed = array_map(function ($feed) {
-
preg_match('/at:\/\/(did:plc:[a-z0-9]+)\/app.bsky.feed.post\/([a-z0-9]+)/', $feed->post, $uriComponents);
-
$did = $uriComponents[1];
-
$rkey = $uriComponents[2];
-
return $this->getPost($did, $rkey, true);
-
}, $body->feed);*/
return $body;
}
···
}
function getReplyRecords(string $post):array {
-
/*$ret = $this->getConstellationLinkData($post, "app.bsky.feed.post", ".reply.root.uri");
+
$ret = $this->getConstellationLinkData($post, "app.bsky.feed.post", ".reply.root.uri");
if ($ret) {
-
return array_map(function ($rec) {
-
$slingshotRecord = $this->getSlingshotData($rec->did, $rec->collection, $rec->rkey, ['reverse' => true]);
-
return $this->sanitizePost($slingshotRecord, true);
-
}, $ret->linking_records);
-
}*/
+
return await(all(array_map(function ($rec) {
+
return async(fn() => $this->sanitizePost($this->getSlingshotData($rec->did, $rec->collection, $rec->rkey, ['reverse' => true]), true));
+
}, $ret->linking_records)));
+
}
return [];
}
···
'cursor' => $cursor
]);
if (!$postData) return false;
-
$postData = array_map(function($p) {
+
$postData = await(all(array_map(function($p) {
$uriComponents = $this->splitAtUri($p->uri);
$cache = \requestPostCache($uriComponents->rkey);
if ($cache) return $this->sanitizeCachedPost($cache);
-
$post = $this->getPost($uriComponents->did, $uriComponents->rkey, true);
-
return $post;
-
}, $postData->records);
+
return async(fn() => $this->getPost($uriComponents->did, $uriComponents->rkey, true));
+
}, $postData->records)));
return $postData;
}
···
$rkey = $uriComponents[2];
$authorInfo = $this->getUserInfo($did, 'did');
$facets = property_exists($post->value, 'facets') ? $this->sanitizeFacets($post->value->facets) : [];
+
$waitingFor = await(all([
+
'authorInfo' => async(fn() => $this->getUserInfo($did, 'did')),
+
'replyCount' => async(fn() => $this->getReplies($post->uri)),
+
'repostCount' => async(fn() => $this->getReposts($post->uri)),
+
'likeCount' => async(fn() => $this->getLikes($post->uri)),
+
'quoteCount' => async(fn() => $this->getQuotes($post->uri))
+
]));
$ret = (object) [
'author' => (object) [
-
'displayName' => $authorInfo->displayName,
-
'handle' => $authorInfo->handle,
-
'avatar' => $authorInfo->avatar,
+
'displayName' => $waitingFor['authorInfo']->displayName,
+
'handle' => $waitingFor['authorInfo']->handle,
+
'avatar' => $waitingFor['authorInfo']->avatar,
'did' => $did,
-
'profileLink' => '/u/'.$authorInfo->handle,
+
'profileLink' => '/u/'.$waitingFor['authorInfo']->handle,
],
'uri' => $post->uri,
'pds' => $authorInfo->pds,
'postId' => $rkey,
'postLink' => '/u/'.$authorInfo->handle.'/'.$rkey,
'content' => property_exists($post->value, 'text') ? $this->applyFacets($post->value->text, $facets) : '',
-
'replyCount' => $this->getReplies($post->uri),
-
'repostCount' => $this->getReposts($post->uri),
-
'likeCount' => $this->getLikes($post->uri),
-
'quoteCount' => $this->getQuotes($post->uri),
+
'replyCount' => $waitingFor['replyCount'],
+
'repostCount' => $waitingFor['repostCount'],
+
'likeCount' => $waitingFor['likeCount'],
+
'quoteCount' => $waitingFor['quoteCount'],
'createdAt' => $post->value->createdAt,
'embedType' => property_exists($post->value, 'embed') ? $post->value->embed->{'$type'} : null,
'embeds' => property_exists($post->value, 'embed') ? $this->sanitizeEmbeds($post->value->embed, $authorInfo) : [],