Handle large messages with tweaked json decoding of ShowRequest handling.

This commit is contained in:
Bill Thiede 2023-02-27 21:29:40 -08:00
parent 25541bc1ca
commit d8275debdc
4 changed files with 75 additions and 46 deletions

5
Cargo.lock generated
View File

@ -980,6 +980,7 @@ dependencies = [
"notmuch", "notmuch",
"seed", "seed",
"serde", "serde",
"serde_json",
"wasm-bindgen-test", "wasm-bindgen-test",
] ]
@ -1782,9 +1783,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.87" version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",

View File

@ -23,6 +23,7 @@ console_log = {git = "http://git-private.h.xinu.tv/wathiede/console_log.git"}
serde = { version = "1.0.147", features = ["derive"] } serde = { version = "1.0.147", features = ["derive"] }
notmuch = {path = "../notmuch"} notmuch = {path = "../notmuch"}
itertools = "0.10.5" itertools = "0.10.5"
serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
[package.metadata.wasm-pack.profile.release] [package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Os'] wasm-opt = ['-Os']

View File

@ -14,6 +14,7 @@
} }
.body { .body {
padding-bottom: 1em; padding-bottom: 1em;
border: 1px red solid;
} }
.error { .error {
background-color: red; background-color: red;
@ -30,6 +31,9 @@ iframe {
} }
.index .subject { .index .subject {
} }
.index .date {
white-space: nowrap;
}
</style> </style>
</head> </head>

View File

@ -7,6 +7,7 @@ use itertools::Itertools;
use log::{debug, error, info, warn, Level}; use log::{debug, error, info, warn, Level};
use notmuch::{Content, Part, SearchSummary, Thread, ThreadNode, ThreadSet}; use notmuch::{Content, Part, SearchSummary, Thread, ThreadNode, ThreadSet};
use seed::{prelude::*, *}; use seed::{prelude::*, *};
use serde::de::Deserialize;
// ------ ------ // ------ ------
// Init // Init
@ -113,7 +114,6 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
} }
async fn search_request(query: &str) -> fetch::Result<SearchSummary> { async fn search_request(query: &str) -> fetch::Result<SearchSummary> {
info!("making search request for '{}'", query);
Request::new(api::search(query)) Request::new(api::search(query))
.method(Method::Get) .method(Method::Get)
.fetch() .fetch()
@ -137,13 +137,17 @@ mod api {
} }
async fn show_request(tid: &str) -> fetch::Result<ThreadSet> { async fn show_request(tid: &str) -> fetch::Result<ThreadSet> {
Request::new(api::show(tid)) let b = Request::new(api::show(tid))
.method(Method::Get) .method(Method::Get)
.fetch() .fetch()
.await? .await?
.check_status()? .check_status()?
.json() .bytes()
.await .await?;
let mut deserializer = serde_json::Deserializer::from_slice(&b);
deserializer.disable_recursion_limit();
Ok(ThreadSet::deserialize(&mut deserializer)
.map_err(|_| FetchError::JsonError(fetch::JsonError::Serde(JsValue::NULL)))?)
} }
// ------ ------ // ------ ------
@ -279,16 +283,29 @@ fn tags_chiclet(tags: &[String]) -> impl Iterator<Item = Node<Msg>> + '_ {
fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ { fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
let authors = authors.split(','); let authors = authors.split(',');
/*
if authors.len() == 1 {
return authors.iter().filter_map(|author| {
Some(span![
attrs! {
At::Title => author.trim()},
author
])
});
}
*/
authors authors
.map(|author| { .filter_map(|author| {
author.split_whitespace().nth(0).map(|first| {
span![ span![
attrs! { attrs! {
At::Title => author}, At::Title => author.trim()},
author.split_whitespace().nth(0) first
] ]
}) })
.into() })
.iterleave(itertools::repeat_n(",", authors.len()).map(|c| span![c])) .intersperse(span![", "])
} }
fn view_search_results(query: &str, search_results: &SearchSummary) -> Node<Msg> { fn view_search_results(query: &str, search_results: &SearchSummary) -> Node<Msg> {
@ -302,11 +319,10 @@ fn view_search_results(query: &str, search_results: &SearchSummary) -> Node<Msg>
tr![ tr![
td![ td![
C!["from"], C!["from"],
//pretty_authors(&r.authors), pretty_authors(&r.authors),
&r.authors,
IF!(r.total>1 => small![" ", r.total.to_string()]), IF!(r.total>1 => small![" ", r.total.to_string()]),
], ],
td![C!["subject"], tags_chiclet(&r.tags), &r.subject], td![C!["subject"], tags_chiclet(&r.tags), " ", &r.subject],
td![C!["date"], &r.date_relative], td![C!["date"], &r.date_relative],
ev(Ev::Click, move |_| Msg::ShowRequest(tid)), ev(Ev::Click, move |_| Msg::ShowRequest(tid)),
] ]
@ -381,6 +397,11 @@ fn view_header(query: &str) -> Node<Msg> {
let query = query.to_string(); let query = query.to_string();
nav![ nav![
C!["navbar"], C!["navbar"],
attrs! {At::Role=>"navigation"},
div![
C!["navbar-menu"],
div![
C!["navbar-start"],
a![ a![
C!["navbar-item", "button",], C!["navbar-item", "button",],
"Unread", "Unread",
@ -405,7 +426,9 @@ fn view_header(query: &str) -> Node<Msg> {
} else { } else {
Msg::Noop Msg::Noop
}), }),
], ]
]
]
] ]
} }
@ -417,11 +440,11 @@ fn view(model: &Model) -> Node<Msg> {
Context::Thread(thread_set) => view_thread(thread_set), Context::Thread(thread_set) => view_thread(thread_set),
Context::Search(search_results) => view_search_results(&model.query, search_results), Context::Search(search_results) => view_search_results(&model.query, search_results),
}; };
div![section![
section![
C!["section"], C!["section"],
div![C!["container"], view_header(&model.query), content] view_header(&model.query),
] div![C!["container"], content]
]]
} }
// ------ ------ // ------ ------