aboutsummaryrefslogtreecommitdiff
path: root/import/src/db.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-05-12 11:46:16 +0200
committermetamuffin <metamuffin@disroot.org>2024-05-12 11:46:16 +0200
commitcfaae9067c151d8db49b0fcbcaff04bc31176bd2 (patch)
tree4b2727167d58f58c06384b9302404b1d2f7d54e8 /import/src/db.rs
parentbf0e9de8eb801ef58a3820b663d30bb55762970e (diff)
downloadjellything-cfaae9067c151d8db49b0fcbcaff04bc31176bd2.tar
jellything-cfaae9067c151d8db49b0fcbcaff04bc31176bd2.tar.bz2
jellything-cfaae9067c151d8db49b0fcbcaff04bc31176bd2.tar.zst
mostly ignore errors when importing
Diffstat (limited to 'import/src/db.rs')
-rw-r--r--import/src/db.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/import/src/db.rs b/import/src/db.rs
index e6174e4..87350ac 100644
--- a/import/src/db.rs
+++ b/import/src/db.rs
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Context};
use jellybase::database::{
- redb::ReadableTable,
+ redb::{ReadableTable, ReadableTableMetadata},
tantivy::{doc, DateTime},
DataAcid, Ser, T_NODE, T_NODE_EXTENDED, T_NODE_IMPORT,
};
@@ -21,6 +21,7 @@ pub(crate) trait ImportStorage: Sync {
fn get_partial_parts(&self, id: &str) -> anyhow::Result<Vec<(Vec<usize>, Node)>>;
fn insert_complete_node(&self, id: &str, node: Node) -> anyhow::Result<()>;
+ fn pre_clean(&self) -> anyhow::Result<()>;
fn remove_prev_nodes(&self) -> anyhow::Result<()>;
fn finish(&self) -> anyhow::Result<()>;
}
@@ -34,6 +35,17 @@ impl<'a> DatabaseStorage<'a> {
}
}
impl ImportStorage for DatabaseStorage<'_> {
+ fn pre_clean(&self) -> anyhow::Result<()> {
+ let txn = self.db.begin_write()?;
+ let mut table = txn.open_table(T_NODE_IMPORT)?;
+ if !table.is_empty()? {
+ info!("clearing temporary node tree from an aborted last import...");
+ table.retain(|_, _| false)?;
+ }
+ drop(table);
+ txn.commit()?;
+ Ok(())
+ }
fn remove_prev_nodes(&self) -> anyhow::Result<()> {
info!("removing old nodes...");
let txn = self.db.inner.begin_write()?;
@@ -107,6 +119,9 @@ impl<'a> MemoryStorage<'a> {
}
}
impl ImportStorage for MemoryStorage<'_> {
+ fn pre_clean(&self) -> anyhow::Result<()> {
+ Ok(())
+ }
fn remove_prev_nodes(&self) -> anyhow::Result<()> {
info!("removing old nodes...");
let txn = self.db.inner.begin_write()?;