diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-02-05 21:17:54 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-02-05 21:17:54 +0100 |
| commit | 8ec94477fb5efae62dcfee31cede87eb400bf02d (patch) | |
| tree | e36ec2227076a8857495647f6abcb9883f154d6f /import/src/lib.rs | |
| parent | 65ca3f3450d0067668111f6e13cc3089768c9efe (diff) | |
| download | jellything-8ec94477fb5efae62dcfee31cede87eb400bf02d.tar jellything-8ec94477fb5efae62dcfee31cede87eb400bf02d.tar.bz2 jellything-8ec94477fb5efae62dcfee31cede87eb400bf02d.tar.zst | |
migrate import to new db trait
Diffstat (limited to 'import/src/lib.rs')
| -rw-r--r-- | import/src/lib.rs | 82 |
1 files changed, 34 insertions, 48 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs index bb401d3..4ad7f25 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -18,11 +18,7 @@ use jellycommon::{ jellyobject::{self, ObjectBuffer, Path as TagPath, fields}, *, }; -use jellydb::{ - kv::Store, - query::{Filter, Query, Sort}, - table::{RowNum, Table}, -}; +use jellydb::{Database, Filter, Query, RowNum, Sort}; use jellyremuxer::{ demuxers::create_demuxer_autodetect, matroska::{self, AttachedFile, Segment}, @@ -86,9 +82,7 @@ pub fn is_importing() -> bool { #[derive(Clone)] pub struct ImportConfig { pub cache: Arc<Cache>, - pub db: Arc<dyn Store>, - pub nodes: Arc<Table>, - pub import_meta: Arc<Table>, + pub db: Arc<dyn Database>, } fields! { @@ -110,9 +104,9 @@ impl ImportConfig { mut update: impl FnMut(ObjectBuffer) -> ObjectBuffer, ) -> Result<()> { self.db.transaction(&mut |txn| { - let ob_before = self.nodes.get(txn, node)?.unwrap(); + let ob_before = txn.get(node)?.unwrap(); let ob_after = update(ob_before); - self.nodes.update(txn, node, ob_after)?; + txn.update(node, ob_after)?; Ok(()) })?; Ok(()) @@ -124,25 +118,23 @@ impl ImportConfig { ) -> Result<RowNum> { let mut row = 0; self.db.transaction(&mut |txn| { - row = match self.nodes.query_single(txn, node_slug_query(slug))? { + row = match txn.query_single(node_slug_query(slug))? { Some(r) => r, - None => self - .nodes - .insert(txn, ObjectBuffer::new(&mut [(NO_SLUG.0, &slug)]))?, + None => txn.insert(ObjectBuffer::new(&mut [(NO_SLUG.0, &slug)]))?, }; - let node = self.nodes.get(txn, row)?.unwrap(); + let node = txn.get(row)?.unwrap(); let node = update(node); let node = node.as_object().insert(NO_SLUG, slug); - self.nodes.update(txn, row, node)?; + txn.update(row, node)?; Ok(()) })?; Ok(row) } pub fn get_node(&self, node: RowNum) -> Result<Option<ObjectBuffer>> { let mut buf = None; - self.db.read_transaction(&mut |txn| { - buf = self.nodes.get(txn, node)?; + self.db.transaction(&mut |txn| { + buf = txn.get(node)?; Ok(()) })?; Ok(buf) @@ -420,8 +412,8 @@ fn process_node( node: RowNum, ) { let mut slug = String::new(); - reporting::catch(dba.db.read_transaction(&mut |txn| { - let no = dba.nodes.get(txn, node)?.unwrap(); + reporting::catch(dba.db.transaction(&mut |txn| { + let no = txn.get(node)?.unwrap(); if let Some(s) = no.as_object().get(NO_SLUG) { slug = s.to_owned(); } @@ -452,20 +444,17 @@ fn compare_mtime(dba: &ImportConfig, path: &Path) -> Result<bool> { let meta = path.metadata()?; let mtime = meta.modified()?.duration_since(UNIX_EPOCH)?.as_secs(); let mut was_changed = false; - dba.db.read_transaction(&mut |txn| { - match dba.import_meta.query_single( - txn, - Query { - filter: Filter::Match( - TagPath(vec![IM_PATH.0]), - path.as_os_str().as_encoded_bytes().to_vec(), - ), - sort: Sort::None, - }, - )? { + dba.db.transaction(&mut |txn| { + match txn.query_single(Query { + filter: Filter::Match( + TagPath(vec![IM_PATH.0]), + path.as_os_str().as_encoded_bytes().to_vec(), + ), + sort: Sort::None, + })? { None => was_changed = true, Some(row) => { - let meta = dba.import_meta.get(txn, row)?.unwrap(); + let meta = txn.get(row)?.unwrap(); let prev_mtime = meta.as_object().get(IM_MTIME).unwrap_or_default(); was_changed = mtime > prev_mtime } @@ -479,26 +468,23 @@ fn update_mtime(dba: &ImportConfig, path: &Path) -> Result<()> { let meta = path.metadata()?; let mtime = meta.modified()?.duration_since(UNIX_EPOCH)?.as_secs(); dba.db.transaction(&mut |txn| { - let row = match dba.import_meta.query_single( - txn, - Query { - filter: Filter::Match( - TagPath(vec![IM_PATH.0]), - path.as_os_str().as_encoded_bytes().to_vec(), - ), - sort: Sort::None, - }, - )? { + let row = match txn.query_single(Query { + filter: Filter::Match( + TagPath(vec![IM_PATH.0]), + path.as_os_str().as_encoded_bytes().to_vec(), + ), + sort: Sort::None, + })? { Some(row) => row, - None => dba.import_meta.insert( - txn, - ObjectBuffer::new(&mut [(IM_PATH.0, &path.as_os_str().as_encoded_bytes())]), - )?, + None => txn.insert(ObjectBuffer::new(&mut [( + IM_PATH.0, + &path.as_os_str().as_encoded_bytes(), + )]))?, }; - let mut ob = dba.import_meta.get(txn, row)?.unwrap(); + let mut ob = txn.get(row)?.unwrap(); ob = ob.as_object().insert(IM_MTIME, mtime); - dba.import_meta.update(txn, row, ob)?; + txn.update(row, ob)?; Ok(()) })?; |