Skip to content

Commit

Permalink
bugfix for bulk replace of trait relations
Browse files Browse the repository at this point in the history
  • Loading branch information
maximiliancsuk committed May 10, 2024
1 parent bb08044 commit 4ce6921
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
7 changes: 2 additions & 5 deletions backend/Omnikeeper.Base/Model/TraitBased/TraitEntityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,10 @@ public async Task<bool> BulkReplaceAttributesOnly(ICIIDSelection relevantCIs, IE
* and will be considered as this trait's entities going forward
*/
// NOTE: the cis MUST exist already
public async Task<bool> BulkReplaceRelationsOnly(IEnumerable<BulkRelationFullFragment> fragments, IReadOnlySet<Guid> relevantCIIDs,
public async Task<bool> BulkReplaceRelationsOnly(IList<(Guid thisCIID, string predicateID, Guid[] otherCIIDs)> fragments, ISet<(Guid thisCIID, string predicateID)> relevant, bool outgoing,
LayerSet layerSet, string writeLayer, IChangesetProxy changesetProxy, IModelContext trans, IMaskHandlingForRemoval maskHandlingForRemoval)
{
if (relevantCIIDs.IsEmpty())
return false;

var scope = new BulkRelationDataCIScope(writeLayer, fragments, relevantCIIDs);
var scope = new BulkRelationDataCIAndPredicateScope(writeLayer, fragments, relevant, outgoing);
return await WriteRelations(scope, layerSet, writeLayer, changesetProxy, trans, maskHandlingForRemoval);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,9 @@ public void Init(GraphQLMutation tet, TypeContainer typeContainer)
if (await authzFilterManager.ApplyPreFilterForMutation(new PreUpsertContextForTraitEntities(relevantCIID, elementTypeContainer.Trait), writeLayerID, userContext, context.Path) is AuthzFilterResultDeny d)
throw new ExecutionError(d.Reason);
var fragments = input.SelectMany(i => i.RelatedCIIDs.Select(rc => new BulkRelationFullFragment(i.BaseCIID, rc, tr.RelationTemplate.PredicateID, false)));
var changed = await elementTypeContainer.TraitEntityModel.BulkReplaceRelationsOnly(fragments, relevantCIIDs, layerset, writeLayerID, userContext.ChangesetProxy, trans, MaskHandlingForRemovalApplyNoMask.Instance);
var fragments = input.Select(i => (i.BaseCIID, tr.RelationTemplate.PredicateID, i.RelatedCIIDs)).ToList();
var relevant = relevantCIIDs.Select(ciid => (ciid, tr.RelationTemplate.PredicateID)).ToHashSet();
var changed = await elementTypeContainer.TraitEntityModel.BulkReplaceRelationsOnly(fragments, relevant, tr.RelationTemplate.DirectionForward, layerset, writeLayerID, userContext.ChangesetProxy, trans, MaskHandlingForRemovalApplyNoMask.Instance);
var changeset = userContext.ChangesetProxy.GetActiveChangeset(writeLayerID);
foreach (var relevantCIID in relevantCIIDs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public async Task TestBasics()
directionForward: true
traitHints: [""test_trait_a""]
}
},
{
identifier: ""unrelated""
template: {
predicateID: ""is_unrelated_to""
directionForward: true
traitHints: [""test_trait_a""]
}
}
],
requiredTraits: []
Expand Down Expand Up @@ -106,6 +114,24 @@ public async Task TestBasics()
AssertQuerySuccess(initialBulkInsert, @"{ ""bulkReplace_test_trait_a"": { ""isNoOp"": false } }", user);


// setup unrelated relations
var mutationBulkReplaceUnrelated = @"
mutation {
bulkReplaceRelations_test_trait_a_unrelated(
layers: [""layer_1""]
writeLayer: ""layer_1""
input: [
{baseCIID: ""e4125f12-0257-4835-aa25-b8f83a64a38c"", relatedCIIDs: [""eb3772f6-6d3e-426b-86f3-1ff8ba165d0c""]},
{baseCIID: ""eb3772f6-6d3e-426b-86f3-1ff8ba165d0c"", relatedCIIDs: [""e4125f12-0257-4835-aa25-b8f83a64a38c"", ""fb3772f6-6d3e-426b-86f3-1ff8ba165d0c""]}]
) {
isNoOp
}
}
";
AssertQuerySuccess(mutationBulkReplaceUnrelated, @"{ ""bulkReplaceRelations_test_trait_a_unrelated"": { ""isNoOp"": false } }", user);



var expectedNoop = @"{ ""bulkReplaceRelations_test_trait_a_assignments"": { ""isNoOp"": true } }";
var expectedOp = @"{ ""bulkReplaceRelations_test_trait_a_assignments"": { ""isNoOp"": false } }";

Expand Down Expand Up @@ -158,6 +184,7 @@ public async Task TestBasics()
name
optional
assignments { relatedCIID }
unrelated { relatedCIID }
}
}
}
Expand All @@ -169,9 +196,9 @@ public async Task TestBasics()
""traitEntities"": {
""test_trait_a"": {
""all"": [
{ ""entity"": { ""id"": 1, ""name"": ""testname_a"", ""optional"": null, ""assignments"": [] } },
{ ""entity"": { ""id"": 2, ""name"": ""testname_b"", ""optional"": null, ""assignments"": [{""relatedCIID"": ""e4125f12-0257-4835-aa25-b8f83a64a38c""}] } },
{ ""entity"": { ""id"": 3, ""name"": ""testname_c"", ""optional"": null, ""assignments"": [{""relatedCIID"": ""eb3772f6-6d3e-426b-86f3-1ff8ba165d0c""}, {""relatedCIID"": ""e4125f12-0257-4835-aa25-b8f83a64a38c""}] } }
{ ""entity"": { ""id"": 1, ""name"": ""testname_a"", ""optional"": null, ""assignments"": [], ""unrelated"": [{""relatedCIID"": ""eb3772f6-6d3e-426b-86f3-1ff8ba165d0c""}] } },
{ ""entity"": { ""id"": 2, ""name"": ""testname_b"", ""optional"": null, ""assignments"": [{""relatedCIID"": ""e4125f12-0257-4835-aa25-b8f83a64a38c""}], ""unrelated"": [{""relatedCIID"": ""e4125f12-0257-4835-aa25-b8f83a64a38c""}, {""relatedCIID"": ""fb3772f6-6d3e-426b-86f3-1ff8ba165d0c""}] } },
{ ""entity"": { ""id"": 3, ""name"": ""testname_c"", ""optional"": null, ""assignments"": [{""relatedCIID"": ""eb3772f6-6d3e-426b-86f3-1ff8ba165d0c""}, {""relatedCIID"": ""e4125f12-0257-4835-aa25-b8f83a64a38c""}], ""unrelated"": [] } }
]
}
}
Expand Down

0 comments on commit 4ce6921

Please sign in to comment.