aboutsummaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/Cargo.toml1
-rw-r--r--base/src/cache.rs8
-rw-r--r--base/src/database.rs21
3 files changed, 27 insertions, 3 deletions
diff --git a/base/Cargo.toml b/base/Cargo.toml
index e897404..6474e25 100644
--- a/base/Cargo.toml
+++ b/base/Cargo.toml
@@ -19,6 +19,7 @@ redb = "2.4.0"
tantivy = "0.22.0"
serde_json = "1.0.138"
aes-gcm-siv = "0.11.1"
+humansize = "2.1.3"
[features]
db_json = []
diff --git a/base/src/cache.rs b/base/src/cache.rs
index d6aa15f..0b28e1b 100644
--- a/base/src/cache.rs
+++ b/base/src/cache.rs
@@ -44,7 +44,8 @@ pub fn cache_location(seed: &[&str]) -> (usize, CachePath) {
d.update(b"\0");
}
let d = d.finalize();
- let n = d[0] as usize | ((d[1] as usize) << 8) | ((d[2] as usize) << 16) | ((d[3] as usize) << 24);
+ let n =
+ d[0] as usize | ((d[1] as usize) << 8) | ((d[2] as usize) << 16) | ((d[3] as usize) << 24);
let fname = base64::engine::general_purpose::URL_SAFE.encode(d);
let fname = &fname[..22];
let fname = format!("{}-{}", seed[0], fname); // about 128 bits
@@ -269,5 +270,8 @@ pub fn cleanup_cache() {
CACHE_IN_MEMORY_SIZE.fetch_sub(reduction, Ordering::Relaxed);
drop(g);
- info!("done");
+ info!(
+ "done, {} freed",
+ humansize::format_size(reduction, humansize::DECIMAL)
+ );
}
diff --git a/base/src/database.rs b/base/src/database.rs
index 32f1464..c3ca5d4 100644
--- a/base/src/database.rs
+++ b/base/src/database.rs
@@ -35,6 +35,7 @@ const T_INVITE: TableDefinition<&str, ()> = TableDefinition::new("invite");
const T_NODE: TableDefinition<[u8; 32], Ser<Node>> = TableDefinition::new("node");
const T_NODE_CHILDREN: TableDefinition<([u8; 32], [u8; 32]), ()> =
TableDefinition::new("node_children");
+const T_TAG_NODE: TableDefinition<(&str, [u8; 32]), ()> = TableDefinition::new("tag_node");
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");
@@ -109,6 +110,14 @@ impl Database {
.map(|r| r.map(|r| NodeID(r.0.value().1)))
.collect::<Result<Vec<_>, StorageError>>()?)
}
+ pub fn get_tag_nodes(&self, tag: &str) -> Result<Vec<NodeID>> {
+ let txn = self.inner.begin_read()?;
+ let t_tag_node = txn.open_table(T_TAG_NODE)?;
+ Ok(t_tag_node
+ .range((tag, NodeID::MIN.0)..(tag, NodeID::MAX.0))?
+ .map(|r| r.map(|r| NodeID(r.0.value().1)))
+ .collect::<Result<Vec<_>, StorageError>>()?)
+ }
pub fn get_nodes_modified_since(&self, since: u64) -> Result<Vec<NodeID>> {
let txn = self.inner.begin_read()?;
let t_node_mtime = txn.open_table(T_NODE_MTIME)?;
@@ -171,6 +180,7 @@ impl Database {
let mut t_node_mtime = txn.open_table(T_NODE_MTIME)?;
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_tag_node = txn.open_table(T_TAG_NODE)?;
let mut node = t_node.get(id.0)?.map(|v| v.value().0).unwrap_or_default();
let mut dh_before = HashWriter(DefaultHasher::new());
@@ -189,9 +199,18 @@ impl Database {
for (pl, eid) in &node.external_ids {
t_node_external_id.insert((pl.as_str(), eid.as_str()), id.0)?;
}
+ for tag in &node.tags {
+ t_tag_node.insert((tag.as_str(), id.0), ())?;
+ }
t_node.insert(&id.0, Ser(node))?;
t_node_mtime.insert(&id.0, time)?;
- drop((t_node, t_node_mtime, t_node_children, t_node_external_id));
+ drop((
+ t_node,
+ t_node_mtime,
+ t_node_children,
+ t_node_external_id,
+ t_tag_node,
+ ));
txn.set_durability(Durability::Eventual);
txn.commit()?;
Ok(())