aboutsummaryrefslogtreecommitdiff
path: root/database/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-11-18 12:08:34 +0100
committermetamuffin <metamuffin@disroot.org>2025-11-18 12:08:34 +0100
commitbac47e456085ea153ae6ae1b1e28e41868693c9c (patch)
tree062c157d66faa3935c1175433732d30c07d1cd5b /database/src
parentf3af9263b0472bcef3207906ce0e4d1d4aa3595b (diff)
downloadjellything-bac47e456085ea153ae6ae1b1e28e41868693c9c.tar
jellything-bac47e456085ea153ae6ae1b1e28e41868693c9c.tar.bz2
jellything-bac47e456085ea153ae6ae1b1e28e41868693c9c.tar.zst
start reworking model
Diffstat (limited to 'database/src')
-rw-r--r--database/src/lib.rs65
1 files changed, 8 insertions, 57 deletions
diff --git a/database/src/lib.rs b/database/src/lib.rs
index 8e47298..fe43ad4 100644
--- a/database/src/lib.rs
+++ b/database/src/lib.rs
@@ -6,7 +6,6 @@
pub mod search;
use anyhow::{Context, Result, anyhow, bail};
-use bincode::{Decode, Encode, config::standard};
use jellycommon::{
Node, NodeID,
user::{NodeUserData, User},
@@ -14,6 +13,8 @@ use jellycommon::{
use log::info;
use redb::{Durability, ReadableDatabase, ReadableTable, StorageError, TableDefinition};
use search::NodeTextSearchIndex;
+#[cfg(not(feature = "db_json"))]
+use serde::{Serialize, de::DeserializeOwned};
use std::{
fs::create_dir_all,
hash::{DefaultHasher, Hasher},
@@ -185,21 +186,19 @@ impl Database {
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());
- bincode::encode_into_writer(&node, &mut dh_before, standard()).unwrap();
+ let dh_before = serde_json::to_vec(&node).unwrap();
update(&mut node)?;
- let mut dh_after = HashWriter(DefaultHasher::new());
- bincode::encode_into_writer(&node, &mut dh_after, standard()).unwrap();
+ let dh_after = serde_json::to_vec(&node).unwrap();
- if dh_before.0.finish() == dh_after.0.finish() {
+ if dh_before == dh_after {
return Ok(());
}
for parent in &node.parents {
t_node_children.insert((parent.0, id.0), ())?;
}
- for (pl, eid) in &node.external_ids {
- t_node_external_id.insert((pl.as_str(), eid.as_str()), id.0)?;
+ for (pl, eid) in &node.identifiers.0 {
+ t_node_external_id.insert((pl.to_string().as_str(), eid.as_str()), id.0)?;
}
for tag in &node.tags {
t_tag_node.insert((tag.as_str(), id.0), ())?;
@@ -468,59 +467,11 @@ impl Database {
}
}
-pub struct HashWriter(DefaultHasher);
-impl bincode::enc::write::Writer for HashWriter {
- fn write(&mut self, bytes: &[u8]) -> std::result::Result<(), bincode::error::EncodeError> {
- self.0.write(bytes);
- Ok(())
- }
-}
-
#[derive(Debug)]
#[cfg(not(feature = "db_json"))]
pub struct Ser<T>(pub T);
#[cfg(not(feature = "db_json"))]
-impl<T: Encode + Decode<()> + std::fmt::Debug> redb::Value for Ser<T> {
- type SelfType<'a>
- = Ser<T>
- where
- Self: 'a;
- type AsBytes<'a>
- = Vec<u8>
- where
- Self: 'a;
-
- fn fixed_width() -> Option<usize> {
- None
- }
-
- fn from_bytes<'a>(data: &'a [u8]) -> Self::SelfType<'a>
- where
- Self: 'a,
- {
- Ser(bincode::decode_from_slice(data, bincode::config::legacy())
- .unwrap()
- .0)
- }
-
- fn as_bytes<'a, 'b: 'a>(value: &'a Self::SelfType<'b>) -> Self::AsBytes<'a>
- where
- Self: 'a,
- Self: 'b,
- {
- bincode::encode_to_vec(&value.0, bincode::config::legacy()).unwrap()
- }
-
- fn type_name() -> redb::TypeName {
- redb::TypeName::new("bincode")
- }
-}
-
-#[derive(Debug)]
-#[cfg(feature = "db_json")]
-pub struct Ser<T>(pub T);
-#[cfg(feature = "db_json")]
-impl<T: Serialize + for<'a> Deserialize<'a> + std::fmt::Debug> redb::Value for Ser<T> {
+impl<T: DeserializeOwned + Serialize + std::fmt::Debug> redb::Value for Ser<T> {
type SelfType<'a>
= Ser<T>
where