diff --git a/lib/src/sparql/dataset.rs b/lib/src/sparql/dataset.rs index 153d4f53..e42486c2 100644 --- a/lib/src/sparql/dataset.rs +++ b/lib/src/sparql/dataset.rs @@ -6,6 +6,7 @@ use crate::storage::numeric_encoder::{ }; use crate::storage::Storage; use std::cell::RefCell; +use std::collections::hash_map::Entry; use std::collections::HashMap; use std::convert::Infallible; use std::iter::empty; @@ -151,13 +152,11 @@ impl DatasetView { } pub fn insert_str(&self, key: &StrHash, value: &str) { - if matches!(self.storage.contains_str(key), Ok(true)) { - return; + if let Entry::Vacant(e) = self.extra.borrow_mut().entry(*key) { + if !matches!(self.storage.contains_str(key), Ok(true)) { + e.insert(value.to_owned()); + } } - self.extra - .borrow_mut() - .entry(*key) - .or_insert_with(|| value.to_owned()); } } diff --git a/lib/src/sparql/update.rs b/lib/src/sparql/update.rs index 59628216..2416f309 100644 --- a/lib/src/sparql/update.rs +++ b/lib/src/sparql/update.rs @@ -134,10 +134,12 @@ impl<'a> SimpleUpdateEvaluator<'a> { Self::convert_ground_quad_pattern(quad, &variables, &tuple, &dataset)? { self.storage.remove(quad.as_ref())?; - // Hack to make sure the triple terms are still available for an insert - dataset.encode_term(quad.subject.as_ref()); - dataset.encode_term(quad.predicate.as_ref()); - dataset.encode_term(quad.object.as_ref()); + if !insert.is_empty() { + // Hack to make sure the triple terms are still available for an insert + dataset.encode_term(quad.subject.as_ref()); + dataset.encode_term(quad.predicate.as_ref()); + dataset.encode_term(quad.object.as_ref()); + } } } for quad in insert { diff --git a/lib/src/storage/mod.rs b/lib/src/storage/mod.rs index 69265d4b..43553f0c 100644 --- a/lib/src/storage/mod.rs +++ b/lib/src/storage/mod.rs @@ -811,7 +811,12 @@ impl Storage { } pub fn contains_str(&self, key: &StrHash) -> std::io::Result { - self.db.contains_key(&self.id2str_cf, &key.to_be_bytes()) + Ok(self + .db + .get(&self.id2str_cf, &key.to_be_bytes())? + .map_or(false, |v| { + i32::from_be_bytes(v[..4].try_into().unwrap()) > 0 + })) } }