feat/orm-diffs
Laurin Weger 3 days ago
parent 952dce50d9
commit e63941054a
No known key found for this signature in database
GPG Key ID: 9B372BB0B792770F
  1. 6
      engine/verifier/src/orm/handle_backend_update.rs
  2. 54
      engine/verifier/src/orm/process_changes.rs
  3. 8
      engine/verifier/src/orm/shape_validation.rs
  4. 6
      sdk/rust/src/tests/orm_patches.rs

@ -286,11 +286,11 @@ fn queue_patches_for_newly_valid_subject(
// Register object for creation.
// Path to object consists of this subject's iri and the path except for the last element.
let mut path_to_subject = vec![tracked_subject.subject_iri.clone()];
if path.len() > 0 {
path_to_subject.extend_from_slice(&path[1..]);
if path.len() > 1 {
path_to_subject.extend_from_slice(&path[..path.len() - 1]);
}
log_debug!("Queuing object creation for path: {:?}", path_to_subject);
// log_debug!("Queuing object creation for path: {:?}", path_to_subject);
// Always create the object itself with its IRI
objects_to_create.insert((

@ -183,22 +183,23 @@ impl Verifier {
// Apply all triples for that subject to the tracked (shape, subject) pair.
// Record the changes.
{
if !change.data_applied {
log_debug!(
"Adding triples to change tracker for subject {}",
subject_iri
);
let orm_subscription = self
.orm_subscriptions
.get_mut(nuri)
.unwrap()
.iter_mut()
.find(|sub| {
sub.shape_type.shape == shape.iri && sub.session_id == session_id
sub.shape_type.shape == *root_shape_iri && sub.session_id == session_id
})
.unwrap();
// Update tracked subjects and modify change objects.
if !change.data_applied {
log_debug!(
"Adding triples to change tracker for subject {}",
subject_iri
);
if let Err(e) = add_remove_triples(
shape.clone(),
subject_iri,
@ -211,20 +212,41 @@ impl Verifier {
panic!();
}
change.data_applied = true;
} else {
log_debug!("not applying triples again for subject {subject_iri}");
}
let orm_subscription = self
.orm_subscriptions
.get_mut(nuri)
// Check if this is the first evaluation round - In that case, set old validity to new one.
// if the object was already validated, don't do so again.
{
let tracked_subject = &mut orm_subscription
.tracked_subjects
.get(*subject_iri)
.unwrap()
.iter_mut()
.find(|sub| {
sub.shape_type.shape == shape.iri && sub.session_id == session_id
})
.get(&shape.iri)
.unwrap()
.write()
.unwrap();
// First run
if !change.data_applied
&& tracked_subject.valid != OrmTrackedSubjectValidity::Pending
{
tracked_subject.prev_valid = tracked_subject.valid.clone();
}
if change.data_applied {
log_debug!("not applying triples again for subject {subject_iri}");
// Has this subject already been validated?
if change.data_applied
&& tracked_subject.valid != OrmTrackedSubjectValidity::Pending
{
log_debug!("Not evaluating subject again {subject_iri}");
continue;
}
}
}
// Validate the subject.
let need_eval = Self::update_subject_validity(change, &shape, orm_subscription);

@ -33,7 +33,6 @@ impl Verifier {
};
let mut tracked_subject = tracked_subject.write().unwrap();
let previous_validity = tracked_subject.prev_valid.clone();
tracked_subject.prev_valid = tracked_subject.valid.clone();
// Keep track of objects that need to be validated against a shape to fetch and validate.
let mut need_evaluation: Vec<(String, String, bool)> = vec![];
@ -45,7 +44,10 @@ impl Verifier {
);
// Check 1) Check if this object is untracked and we need to remove children and ourselves.
if previous_validity == OrmTrackedSubjectValidity::Untracked {
if previous_validity == OrmTrackedSubjectValidity::Untracked
// If .valid is pending, this part was executed before in this validation round.
&& tracked_subject.valid != OrmTrackedSubjectValidity::Pending
{
// 1.1) Schedule children for deletion
// 1.1.1) Set all children to `untracked` that don't have other parents.
for tracked_predicate in tracked_subject.tracked_predicates.values() {
@ -342,6 +344,8 @@ impl Verifier {
};
}
// == End of validation part. Next, process side-effects ==
tracked_subject.valid = new_validity.clone();
if new_validity == OrmTrackedSubjectValidity::Invalid {

@ -29,9 +29,9 @@ async fn test_orm_patch_creation() {
// Tests below all in this test, to prevent waiting times through wallet creation.
// ===
test_patch_add_array(session_id).await;
test_patch_remove_array(session_id).await;
// // ===
// test_patch_add_array(session_id).await;
// test_patch_remove_array(session_id).await;
// // ===
// test_patch_add_nested_1(session_id).await;

Loading…
Cancel
Save