fetch user and feed in parallel when I can
This commit is contained in:
parent
b69a16fff5
commit
0626e6d426
1 changed files with 17 additions and 8 deletions
|
@ -5,6 +5,7 @@ var timeAgo = require('timeago.js');
|
|||
var request = require('request-promise-native')
|
||||
|
||||
// get JSON for an AP URL
|
||||
// TODO make it reject on HTTP 4xx or 5xx
|
||||
async function apGet(url) {
|
||||
return request.get( {
|
||||
uri:url,
|
||||
|
@ -17,8 +18,6 @@ async function apGet(url) {
|
|||
})
|
||||
}
|
||||
|
||||
// accumulate a stream of XML into a html file
|
||||
|
||||
module.exports = async function (opts) {
|
||||
var opts = opts;
|
||||
|
||||
|
@ -30,16 +29,26 @@ module.exports = async function (opts) {
|
|||
throw new Error('need user URL');
|
||||
}
|
||||
|
||||
var user = await apGet(userUrl);
|
||||
var user, feed;
|
||||
|
||||
if (userUrl && !feedUrl) {
|
||||
isIndex = true;
|
||||
var outbox = await apGet(user.outbox);
|
||||
feedUrl = outbox.first;
|
||||
// get user and feed in parallel if I have both URLs
|
||||
if (userUrl && feedUrl){
|
||||
[user, feed] = await Promise.all([ apGet(userUrl), apGet(feedUrl) ]);
|
||||
}else{
|
||||
// get user, then outbox, then feed
|
||||
|
||||
user = await apGet(userUrl);
|
||||
|
||||
if (userUrl && !feedUrl) {
|
||||
isIndex = true;
|
||||
var outbox = await apGet(user.outbox);
|
||||
feedUrl = outbox.first;
|
||||
}
|
||||
|
||||
feed = await apGet(feedUrl);
|
||||
|
||||
}
|
||||
|
||||
var feed = await apGet(feedUrl);
|
||||
|
||||
var templateData = {
|
||||
opts: opts,// from the request
|
||||
|
|
Reference in a new issue