diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-20 00:50:20 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-20 00:50:20 +0100 |
commit | 46c251655db7bb3d9aa814b1a5dde85336b0b9b1 (patch) | |
tree | ab0696f2c92e8854ce6aa0737877cc15184bd8b6 /server/src/routes/ui/browser.rs | |
parent | 1c37d32a0985ff7390313833345b9299f9f0b196 (diff) | |
download | jellything-46c251655db7bb3d9aa814b1a5dde85336b0b9b1.tar jellything-46c251655db7bb3d9aa814b1a5dde85336b0b9b1.tar.bz2 jellything-46c251655db7bb3d9aa814b1a5dde85336b0b9b1.tar.zst |
replace sled with redb
Diffstat (limited to 'server/src/routes/ui/browser.rs')
-rw-r--r-- | server/src/routes/ui/browser.rs | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/server/src/routes/ui/browser.rs b/server/src/routes/ui/browser.rs index 509f242..e811516 100644 --- a/server/src/routes/ui/browser.rs +++ b/server/src/routes/ui/browser.rs @@ -10,9 +10,8 @@ use super::{ node::NodeCard, sort::{filter_and_sort_nodes, NodeFilterSort, NodeFilterSortForm}, }; -use crate::{database::Database, uri}; -use anyhow::Context; -use jellycommon::{user::NodeUserData, NodePublic}; +use crate::{database::DataAcid, uri}; +use jellybase::database::{ReadableTable, T_NODE, T_USER_NODE}; use rocket::{get, State}; /// This function is a stub and only useful for use in the uri! macro. @@ -22,25 +21,31 @@ pub fn r_all_items() {} #[get("/items?<page>&<filter..>")] pub fn r_all_items_filter( sess: Session, - db: &State<Database>, + db: &State<DataAcid>, page: Option<usize>, filter: NodeFilterSort, ) -> Result<DynLayoutPage<'_>, MyError> { - let mut items = db - .node - .iter() - .map(|e| { - let (i, n) = e.context("listing")?; - let u = db - .user_node - .get(&(sess.user.name.clone(), i.clone()))? - .unwrap_or_default(); - Ok((i, n, u)) - }) - .collect::<anyhow::Result<Vec<_>>>()? - .into_iter() - .map(|(k, n, u)| (k, n.public, u)) - .collect::<Vec<(String, NodePublic, NodeUserData)>>(); + let mut items = { + let txn = db.begin_read()?; + let nodes = txn.open_table(T_NODE)?; + let node_users = txn.open_table(T_USER_NODE)?; + let i = nodes + .iter()? + .map(|a| { + let (x, y) = a.unwrap(); + let (x, y) = (x.value().to_owned(), y.value().0); + let z = node_users + .get(&(sess.user.name.as_str(), x.as_str())) + .unwrap() + .map(|z| z.value().0) + .unwrap_or_default(); + let y = y.public; + (x, y, z) + }) + .collect::<Vec<_>>(); + drop(nodes); + i + }; filter_and_sort_nodes(&filter, &mut items); |