diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-16 20:06:01 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-16 20:06:01 +0200 |
commit | d26849375c70c795fdf664f9dfea68c273b6d483 (patch) | |
tree | 53ad4f0eff3604e80b27ff0abf0438ea6c69d432 /base/src/database.rs | |
parent | 1cd966f7454f052fda6c6c9ae1597479f05e23d9 (diff) | |
parent | cdf95d7b80bd2b78895671da8f462145bb5db522 (diff) | |
download | jellything-d26849375c70c795fdf664f9dfea68c273b6d483.tar jellything-d26849375c70c795fdf664f9dfea68c273b6d483.tar.bz2 jellything-d26849375c70c795fdf664f9dfea68c273b6d483.tar.zst |
Merge branch 'rewrite-stream'
Diffstat (limited to 'base/src/database.rs')
-rw-r--r-- | base/src/database.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/base/src/database.rs b/base/src/database.rs index 2909498..c3ca5d4 100644 --- a/base/src/database.rs +++ b/base/src/database.rs @@ -14,7 +14,8 @@ use redb::{Durability, ReadableTable, StorageError, TableDefinition}; use std::{ fs::create_dir_all, hash::{DefaultHasher, Hasher}, - path::Path, + path::{Path, PathBuf}, + str::FromStr, sync::{Arc, RwLock}, time::SystemTime, }; @@ -39,6 +40,8 @@ const T_NODE_EXTERNAL_ID: TableDefinition<(&str, &str), [u8; 32]> = TableDefinition::new("node_external_id"); const T_IMPORT_FILE_MTIME: TableDefinition<&[u8], u64> = TableDefinition::new("import_file_mtime"); const T_NODE_MTIME: TableDefinition<[u8; 32], u64> = TableDefinition::new("node_mtime"); +const T_NODE_MEDIA_PATHS: TableDefinition<([u8; 32], &str), ()> = + TableDefinition::new("node_media_paths"); #[derive(Clone)] pub struct Database { @@ -68,6 +71,7 @@ impl Database { txn.open_table(T_NODE_MTIME)?; txn.open_table(T_NODE_CHILDREN)?; txn.open_table(T_NODE_EXTERNAL_ID)?; + txn.open_table(T_NODE_MEDIA_PATHS)?; txn.open_table(T_IMPORT_FILE_MTIME)?; txn.commit()?; } @@ -132,17 +136,20 @@ impl Database { let mut t_node_children = txn.open_table(T_NODE_CHILDREN)?; let mut t_node_external_id = txn.open_table(T_NODE_EXTERNAL_ID)?; let mut t_import_file_mtime = txn.open_table(T_IMPORT_FILE_MTIME)?; + let mut t_node_media_paths = txn.open_table(T_NODE_MEDIA_PATHS)?; t_node.retain(|_, _| false)?; t_node_mtime.retain(|_, _| false)?; t_node_children.retain(|_, _| false)?; t_node_external_id.retain(|_, _| false)?; t_import_file_mtime.retain(|_, _| false)?; + t_node_media_paths.retain(|_, _| false)?; drop(( t_node, t_node_mtime, t_node_children, t_node_external_id, t_import_file_mtime, + t_node_media_paths, )); txn.set_durability(Durability::Eventual); txn.commit()?; @@ -208,6 +215,24 @@ impl Database { txn.commit()?; Ok(()) } + pub fn get_node_media_paths(&self, id: NodeID) -> Result<Vec<PathBuf>> { + let txn = self.inner.begin_read()?; + let table = txn.open_table(T_NODE_MEDIA_PATHS)?; + let mut paths = Vec::new(); + // TODO fix this + for p in table.range((id.0, "\0")..(id.0, "\x7f"))? { + paths.push(PathBuf::from_str(p?.0.value().1)?); + } + Ok(paths) + } + pub fn insert_node_media_path(&self, id: NodeID, path: &Path) -> Result<()> { + let txn = self.inner.begin_write()?; + let mut table = txn.open_table(T_NODE_MEDIA_PATHS)?; + table.insert((id.0, path.to_str().unwrap()), ())?; + drop(table); + txn.commit()?; + Ok(()) + } pub fn update_node_udata( &self, |