aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2021-09-29 08:36:49 -0400
committerChristine Dodrill <me@christine.website>2021-09-29 08:36:49 -0400
commitec3ca6841cee55944868965fc006e28359f07558 (patch)
treebe78285c802156b53ed2f959aa92ba3d9a45608a
parent4e0d107228888ef707847150b772feb6ebe8c1cc (diff)
downloadxesite-ec3ca6841cee55944868965fc006e28359f07558.tar.xz
xesite-ec3ca6841cee55944868965fc006e28359f07558.zip
use less ram
Signed-off-by: Christine Dodrill <me@christine.website>
-rw-r--r--src/post/mod.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/post/mod.rs b/src/post/mod.rs
index f1fbaef..6e629ab 100644
--- a/src/post/mod.rs
+++ b/src/post/mod.rs
@@ -2,7 +2,7 @@ use chrono::prelude::*;
use color_eyre::eyre::{eyre, Result, WrapErr};
use glob::glob;
use serde::Serialize;
-use std::{cmp::Ordering, path::PathBuf};
+use std::{borrow::Borrow, cmp::Ordering, path::PathBuf};
use tokio::fs;
pub mod frontmatter;
@@ -81,7 +81,7 @@ impl Post {
}
}
-async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
+async fn read_post(dir: &str, fname: PathBuf, cli: &Option<mi::Client>) -> Result<Post> {
let body = fs::read_to_string(fname.clone())
.await
.wrap_err_with(|| format!("can't read {:?}", fname))?;
@@ -98,8 +98,8 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
.with_timezone(&Utc)
.into();
- let mentions: Vec<mi::WebMention> = match std::env::var("MI_TOKEN") {
- Ok(token) => mi::Client::new(token.to_string(), crate::APPLICATION_NAME.to_string())?
+ let mentions: Vec<mi::WebMention> = match cli {
+ Some(cli) => cli
.mentioners(format!("https://christine.website/{}", link))
.await
.map_err(|why| tracing::error!("error: can't load mentions for {}: {}", link, why))
@@ -109,7 +109,7 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
wm.title.as_ref().unwrap_or(&"".to_string()) != &"Bridgy Response".to_string()
})
.collect(),
- Err(_) => vec![],
+ None => vec![],
};
let time_taken = estimated_read_time::text(
@@ -140,9 +140,14 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
}
pub async fn load(dir: &str) -> Result<Vec<Post>> {
+ let cli = match std::env::var("MI_TOKEN") {
+ Ok(token) => mi::Client::new(token.to_string(), crate::APPLICATION_NAME.to_string()).ok(),
+ Err(_) => None,
+ };
+
let futs = glob(&format!("{}/*.markdown", dir))?
.filter_map(Result::ok)
- .map(|fname| read_post(dir, fname));
+ .map(|fname| read_post(dir, fname, cli.borrow()));
let mut result: Vec<Post> = futures::future::join_all(futs)
.await