server: add unread field to tag query.
Optionally fill out unread, as it's expensive.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user