server: add unread field to tag query.

Optionally fill out unread, as it's expensive.
This commit is contained in:
Bill Thiede 2023-11-21 13:15:57 -08:00
parent 64912be4eb
commit ff6675b08f
3 changed files with 15 additions and 17 deletions

21
Cargo.lock generated
View File

@ -437,16 +437,6 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.3"
@ -2235,9 +2225,9 @@ dependencies = [
[[package]]
name = "rayon"
version = "1.7.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
dependencies = [
"either",
"rayon-core",
@ -2245,14 +2235,12 @@ dependencies = [
[[package]]
name = "rayon-core"
version = "1.11.0"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"num_cpus",
]
[[package]]
@ -2730,6 +2718,7 @@ dependencies = [
"glog",
"log 0.4.20",
"notmuch",
"rayon",
"rocket 0.5.0",
"rocket_contrib",
"rocket_cors",

View File

@ -20,6 +20,7 @@ urlencoding = "2.1.3"
async-graphql = "6.0.11"
async-graphql-rocket = "6.0.11"
rocket_cors = "0.6.0"
rayon = "1.8.0"
[dependencies.rocket_contrib]
version = "0.4.11"

View File

@ -6,6 +6,7 @@ use async_graphql::{
};
use log::info;
use notmuch::Notmuch;
use rayon::prelude::*;
pub struct QueryRoot;
@ -36,6 +37,7 @@ struct Tag {
name: String,
fg_color: String,
bg_color: String,
unread: usize,
}
#[Object]
@ -129,15 +131,21 @@ impl QueryRoot {
let nm = ctx.data_unchecked::<Notmuch>();
Ok(nm
.tags()?
.into_iter()
.into_par_iter()
.map(|tag| {
let mut hasher = DefaultHasher::new();
tag.hash(&mut hasher);
let hex = format!("#{:06x}", hasher.finish() % (1 << 24));
let unread = if ctx.look_ahead().field("unread").exists() {
nm.count(&format!("tag:{tag} is:unread")).unwrap_or(0)
} else {
0
};
Tag {
name: tag,
fg_color: "white".to_string(),
bg_color: hex,
unread,
}
})
.collect())