mirror of
https://github.com/fenwick67/mastofeed
synced 2025-02-14 18:50:37 +01:00
fetch user and feed in parallel when I can
This commit is contained in:
parent
b69a16fff5
commit
0626e6d426
@ -5,6 +5,7 @@ var timeAgo = require('timeago.js');
|
|||||||
var request = require('request-promise-native')
|
var request = require('request-promise-native')
|
||||||
|
|
||||||
// get JSON for an AP URL
|
// get JSON for an AP URL
|
||||||
|
// TODO make it reject on HTTP 4xx or 5xx
|
||||||
async function apGet(url) {
|
async function apGet(url) {
|
||||||
return request.get( {
|
return request.get( {
|
||||||
uri:url,
|
uri:url,
|
||||||
@ -17,8 +18,6 @@ async function apGet(url) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// accumulate a stream of XML into a html file
|
|
||||||
|
|
||||||
module.exports = async function (opts) {
|
module.exports = async function (opts) {
|
||||||
var opts = opts;
|
var opts = opts;
|
||||||
|
|
||||||
@ -30,16 +29,26 @@ module.exports = async function (opts) {
|
|||||||
throw new Error('need user URL');
|
throw new Error('need user URL');
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = await apGet(userUrl);
|
var user, feed;
|
||||||
|
|
||||||
|
// 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) {
|
if (userUrl && !feedUrl) {
|
||||||
isIndex = true;
|
isIndex = true;
|
||||||
var outbox = await apGet(user.outbox);
|
var outbox = await apGet(user.outbox);
|
||||||
feedUrl = outbox.first;
|
feedUrl = outbox.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
feed = await apGet(feedUrl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var feed = await apGet(feedUrl);
|
|
||||||
|
|
||||||
var templateData = {
|
var templateData = {
|
||||||
opts: opts,// from the request
|
opts: opts,// from the request
|
||||||
|
Loading…
x
Reference in New Issue
Block a user