Skip to content

Commit

Permalink
Cleanup the excise function a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Oct 14, 2024
1 parent 095ce6f commit f97a905
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/NexusMods.MnemonicDB/InternalTxFunctions/Excise.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.MnemonicDB.Abstractions.IndexSegments;
using NexusMods.MnemonicDB.Abstractions.Query;
using NexusMods.MnemonicDB.Abstractions.TxFunctions;
using NexusMods.MnemonicDB.Storage;

namespace NexusMods.MnemonicDB.InternalTxFunctions;
Expand All @@ -16,11 +14,10 @@ internal class Excise(EntityId[] ids) : AInternalFn
{
public override void Execute(DatomStore store)
{
// Retract all datoms for the given entity ids
var snapshot = store.GetSnapshot();

using IndexSegmentBuilder currentDatomsBuilder = new IndexSegmentBuilder(store.AttributeCache);
using IndexSegmentBuilder historyDatomsBuilder = new IndexSegmentBuilder(store.AttributeCache);
// Find all datoms for the given entity ids
var snapshot = store.CurrentSnapshot;
using var currentDatomsBuilder = new IndexSegmentBuilder(store.AttributeCache);
using var historyDatomsBuilder = new IndexSegmentBuilder(store.AttributeCache);
foreach (var entityId in ids)
{
// All Current datoms
Expand All @@ -32,10 +29,14 @@ public override void Execute(DatomStore store)
historyDatomsBuilder.Add(segment);
}

// Build the datoms
var currentDatoms = currentDatomsBuilder.Build();
var historyDatoms = historyDatomsBuilder.Build();

// Start the batch
var batch = store.Backend.CreateBatch();

// Delete all datoms in the history and current segments
foreach (var datom in historyDatoms)
{
store.EAVTHistory.Delete(batch, datom);
Expand All @@ -55,6 +56,7 @@ public override void Execute(DatomStore store)
}
batch.Commit();

// Push through a marker transaction to make sure all indexes are updated
{
using var builder = new IndexSegmentBuilder(store.AttributeCache);
var txId = EntityId.From(PartitionId.Temp.MakeEntityId(0).Value);
Expand Down

0 comments on commit f97a905

Please sign in to comment.