diff options
author | metamuffin <metamuffin@disroot.org> | 2024-04-15 16:32:27 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-04-15 16:32:27 +0200 |
commit | 2c1b50a1f32c5f87489c2bc03f81e53da8cf3d29 (patch) | |
tree | f626db01a3e025b6402c9c47cec53bfc6b47d87c /import/src/db.rs | |
parent | e38c599bcfe0c052881b78bc141e9f54c75290ea (diff) | |
download | jellything-2c1b50a1f32c5f87489c2bc03f81e53da8cf3d29.tar jellything-2c1b50a1f32c5f87489c2bc03f81e53da8cf3d29.tar.bz2 jellything-2c1b50a1f32c5f87489c2bc03f81e53da8cf3d29.tar.zst |
make search work
Diffstat (limited to 'import/src/db.rs')
-rw-r--r-- | import/src/db.rs | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/import/src/db.rs b/import/src/db.rs index 49c2f0e..c667cf5 100644 --- a/import/src/db.rs +++ b/import/src/db.rs @@ -49,12 +49,7 @@ impl ImportStorage for DatabaseStorage<'_> { Ok(value.value().0) } fn insert_complete_node(&self, id: &str, node: Node) -> anyhow::Result<()> { - let txn_write = self.db.inner.begin_write()?; - let mut t_node = txn_write.open_table(T_NODE)?; - t_node.insert(id, Ser(node))?; - drop(t_node); - txn_write.commit()?; - Ok(()) + insert_complete_node(&self.db, id, node) } fn add_partial_node(&self, id: &str, index_path: &[usize], node: Node) -> anyhow::Result<()> { @@ -92,6 +87,8 @@ impl ImportStorage for DatabaseStorage<'_> { table.drain::<&str>(..)?; drop(table); txn.commit()?; + + self.db.node_index.writer.write().unwrap().commit()?; Ok(()) } } @@ -135,27 +132,7 @@ impl ImportStorage for MemoryStorage<'_> { .to_owned()) } fn insert_complete_node(&self, id: &str, node: Node) -> anyhow::Result<()> { - let txn_write = self.db.inner.begin_write()?; - let mut t_node = txn_write.open_table(T_NODE)?; - t_node.insert(id, Ser(node.clone()))?; - drop(t_node); - txn_write.commit()?; - - self.db - .node_index - .writer - .read() - .unwrap() - .add_document(doc!( - self.db.node_index.id => node.public.id.unwrap_or_default(), - self.db.node_index.title => node.public.title.unwrap_or_default(), - self.db.node_index.description => node.public.description.unwrap_or_default(), - self.db.node_index.releasedate => DateTime::from_timestamp_millis(node.public.release_date.unwrap_or_default()), - self.db.node_index.f_index => node.public.index.unwrap_or_default() as u64, - )) - .context("inserting document")?; - - Ok(()) + insert_complete_node(&self.db, id, node) } fn add_partial_node(&self, id: &str, index_path: &[usize], node: Node) -> anyhow::Result<()> { @@ -184,7 +161,30 @@ impl ImportStorage for MemoryStorage<'_> { } fn finish(&self) -> anyhow::Result<()> { - self.db.node_index.reader.reload()?; + self.db.node_index.writer.write().unwrap().commit()?; Ok(()) } } + +fn insert_complete_node(db: &DataAcid, id: &str, node: Node) -> anyhow::Result<()> { + let txn_write = db.inner.begin_write()?; + let mut t_node = txn_write.open_table(T_NODE)?; + t_node.insert(id, Ser(node.clone()))?; + drop(t_node); + txn_write.commit()?; + + db + .node_index + .writer + .read() + .unwrap() + .add_document(doc!( + db.node_index.id => node.public.id.unwrap_or_default(), + db.node_index.title => node.public.title.unwrap_or_default(), + db.node_index.description => node.public.description.unwrap_or_default(), + db.node_index.releasedate => DateTime::from_timestamp_millis(node.public.release_date.unwrap_or_default()), + db.node_index.f_index => node.public.index.unwrap_or_default() as u64, + )) + .context("inserting document")?; + Ok(()) +} |