Compare commits

..

No commits in common. 'bc0cf6a9e4d9e67941294a8a68b82eed73e8bfc7' and 'a250409458cdcbcb5aa854fce71b4fdb889fbe2e' have entirely different histories.

  1. 2
      app/nextgraph/src-tauri/tauri.conf.json
  2. 54
      engine/verifier/src/orm/mod.rs

@ -14,7 +14,7 @@
"windows": [ "windows": [
{ {
"title": "NextGraph", "title": "NextGraph",
"width": 1024, "width": 800,
"height": 600 "height": 600
} }
], ],

@ -676,11 +676,7 @@ impl Verifier {
// let mut updates = Vec::new(); // let mut updates = Vec::new();
let mut scopes = vec![];
for (scope, subs) in self.orm_subscriptions.iter_mut() { for (scope, subs) in self.orm_subscriptions.iter_mut() {
// Remove old subscriptions
subs.retain(|sub| !sub.sender.is_closed());
if scope.target == NuriTargetV0::UserSite if scope.target == NuriTargetV0::UserSite
|| scope || scope
.overlay .overlay
@ -691,26 +687,16 @@ impl Verifier {
continue; continue;
} }
// prepare to apply updates to tracked subjects and record the changes.
let shapes = subs
.iter()
.map(|sub| {
sub.shape_type
.schema
.get(&sub.shape_type.shape)
.unwrap()
.clone()
})
.collect::<Vec<_>>();
scopes.push((scope.clone(), shapes));
}
for (scope, shapes) in scopes {
let mut orm_changes: OrmChanges = HashMap::new(); let mut orm_changes: OrmChanges = HashMap::new();
// actually applying updates to tracked subjects and record the changes. // Remove old subscriptions
for shape_arc in shapes { subs.retain(|sub| !sub.sender.is_closed());
// Apply updates to tracked subjects and record the changes.
let shape_types = subs.iter().map(|sub| &sub.shape_type);
for shape_type in shape_types {
let shape_arc = shape_type.schema.get(&shape_type.shape).unwrap().clone();
let _ = self.process_changes_for_shape_and_session( let _ = self.process_changes_for_shape_and_session(
&scope, &scope,
shape_arc, shape_arc,
@ -722,8 +708,7 @@ impl Verifier {
); );
} }
let subs = self.orm_subscriptions.get(&scope).unwrap(); for sub in subs.iter_mut() {
for sub in subs.iter() {
// TODO: This if-condition is wrong (intended to not re-apply changes coming from the same subscription). // TODO: This if-condition is wrong (intended to not re-apply changes coming from the same subscription).
if sub.session_id != session_id { if sub.session_id != session_id {
// Create diff from changes & subscription. // Create diff from changes & subscription.
@ -746,18 +731,18 @@ impl Verifier {
let subject_shape = sub.shape_type.schema.get(shape_iri).unwrap(); let subject_shape = sub.shape_type.schema.get(shape_iri).unwrap();
// Iterate over every predicate change and create patches // Iterate over every predicate change and create patches
for (pred_iri, pred_change) in change.predicates.iter() { for (pred_iri, pred_change) in change.predicates {
let pred_shape = subject_shape let pred_shape = subject_shape
.predicates .predicates
.iter() .iter()
.find(|p| p.iri == *pred_iri) .find(|p| p.iri == pred_iri)
.unwrap(); .unwrap();
let is_multi = let is_multi =
pred_shape.maxCardinality > 1 || pred_shape.maxCardinality == -1; pred_shape.maxCardinality > 1 || pred_shape.maxCardinality == -1;
let is_object = let is_object =
pred_shape.dataTypes.iter().any(|dt| !dt.shape.is_none()); pred_shape.dataTypes.iter().any(|dt| !dt.shape.is_none());
let pred_name = pred_shape.readablePredicate.clone(); let pred_name = &pred_shape.readablePredicate;
path.push(pred_name); path.push(pred_name);
let path_str = path.join("/"); let path_str = path.join("/");
@ -814,8 +799,8 @@ impl Verifier {
create_patches_for_changed_subj( create_patches_for_changed_subj(
orm_changes, orm_changes,
patches, patches,
&pred_shape.dataTypes[0].shape.as_ref().unwrap(), // TODO: We need to get to the information which of the object types was validated successfully. &pred_shape.dataTypes[0].shape.unwrap(), // TODO: We need to get to the information which of the object types was validated successfully.
match &pred_change.values_added[0] { match pred_change.values_added[0] {
BasicType::Str(str) => &str, BasicType::Str(str) => &str,
_ => panic!("Nested object should be a string."), _ => panic!("Nested object should be a string."),
}, },
@ -833,15 +818,13 @@ impl Verifier {
} }
} else if is_multi && is_object { } else if is_multi && is_object {
// Add every object added. // Add every object added.
for object_iri_added in pred_change.values_added.iter() { for object_iri_added in pred_change.values_added {
// TODO: As with single object, just that we add the IRI to the path. // TODO: As with single object, just that we add the IRI to the path.
// We also need to check if the object existed before. // We also need to check if the object existed before.
} }
let tracked_predicate =
pred_change.tracked_predicate.read().unwrap();
// Delete every object removed. // Delete every object removed.
if tracked_predicate.tracked_children.len() == 0 { if tracked_predicate.children.len() == 0 {
// Or the whole thing if no children remain // Or the whole thing if no children remain
patches.push(OrmDiffOp { patches.push(OrmDiffOp {
op: OrmDiffOpType::remove, op: OrmDiffOpType::remove,
@ -850,7 +833,7 @@ impl Verifier {
value: None, value: None,
}); });
} else { } else {
for object_iri_removed in pred_change.values_removed.iter() { for object_iri_removed in pred_change.values_removed {
patches.push(OrmDiffOp { patches.push(OrmDiffOp {
op: OrmDiffOpType::remove, op: OrmDiffOpType::remove,
valType: Some(OrmDiffType::object), valType: Some(OrmDiffType::object),
@ -888,14 +871,13 @@ impl Verifier {
} }
// For each tracked subject that has the subscription's shape, call fn above // For each tracked subject that has the subscription's shape, call fn above
for subject_iri in sub.tracked_subjects.iter() { // TODO for subject_iri in sub.tracked_subjects { // TODO
} }
// //
let orm_diff: OrmDiff = vec![]; let orm_diff: OrmDiff = vec![];
let _ = sub let _ = sub
.sender .sender
.clone()
.send(AppResponse::V0(AppResponseV0::OrmUpdate(orm_diff.to_vec()))) .send(AppResponse::V0(AppResponseV0::OrmUpdate(orm_diff.to_vec())))
.await; .await;
} }

Loading…
Cancel
Save