notes: fetch tweets in a nim idiomatic way

This commit is contained in:
HookedBehemoth 2022-07-01 15:44:29 +02:00
parent a9c9622701
commit fd49dd2112
1 changed files with 11 additions and 9 deletions

View File

@ -15,15 +15,17 @@ proc createNotesRouter*(cfg: Config) =
path = getPath()
article = await getGraphArticle(@"id")
let tweets = article
.entities
.filterIt(it.entityType == ArticleEntityType.tweet)
.mapIt(getTweet(it.tweetId))
.all
.await
.filterIt(it != nil)
.mapIt((it.tweet.id, it.tweet))
.toTable
var tweetFutures: seq[Future[Conversation]]
for e in article.entities:
if e.entityType == ArticleEntityType.tweet:
tweetFutures.add getTweet(e.tweetId)
let convs = await tweetFutures.all
var tweets = initTable[int64, Tweet]()
for c in convs:
if c != nil and c.tweet != nil:
tweets[c.tweet.id] = c.tweet
let note = renderNote(article, tweets, path, prefs)
resp renderMain(note, request, cfg, prefs, titleText=article.title)