Skip to content

Commit

Permalink
Fix a bug with empty RecentlyAdded on the first DB created after bo…
Browse files Browse the repository at this point in the history
…otstrapping.
  • Loading branch information
halgari committed Jul 29, 2024
1 parent a1012d3 commit 8248ad6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/NexusMods.MnemonicDB/Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Db(ISnapshot snapshot, TxId txId, AttributeRegistry registry)
_cache = new IndexSegmentCache();
Snapshot = snapshot;
BasisTxId = txId;
RecentlyAdded = new IndexSegment();
RecentlyAdded = snapshot.Datoms(SliceDescriptor.Create(txId, registry));
}

private Db(ISnapshot snapshot, TxId txId, AttributeRegistry registry, RegistryId registryId, IConnection connection, IndexSegmentCache newCache, IndexSegment recentlyAdded)
Expand Down
15 changes: 14 additions & 1 deletion tests/NexusMods.MnemonicDB.Tests/DbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DynamicData;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.Hashing.xxHash64;
using NexusMods.MnemonicDB.Abstractions.BuiltInEntities;
using NexusMods.MnemonicDB.Abstractions.DatomIterators;
using NexusMods.MnemonicDB.Abstractions.Models;
using NexusMods.MnemonicDB.Abstractions.Query;
Expand Down Expand Up @@ -601,7 +602,7 @@ public async Task CanObserveIndexChanges()
var slice = SliceDescriptor.Create(Mod.Name, Connection.Db.Registry);

// Setup the subscription
using var _ = ObservableDatoms.ObserveDatoms(Connection, slice)
using var _ = Connection.ObserveDatoms(slice)
// Snapshot the values each time
.QueryWhenChanged(datoms => datoms.Select(d => d.Resolved.ObjectValue.ToString()!).ToArray())
// Add the changes to the list
Expand All @@ -625,6 +626,18 @@ public async Task CanObserveIndexChanges()
await Verify(changes);
}

[Fact]
public async Task CanGetInitialDbStateFromObservable()
{
var attrs = await Connection.ObserveDatoms(AttributeDefinition.UniqueId).FirstAsync();
attrs.TotalChanges.Should().BeGreaterThan(0);


attrs = await Connection.ObserveDatoms(AttributeDefinition.UniqueId).FirstAsync();
attrs.TotalChanges.Should().BeGreaterThan(0);

}

/// <summary>
/// Test for a flickering bug in UI users, where datoms that are changed result in a `add` and a `remove` operation
/// causing the UI to flicker, instead we want to issue changes on a ScalarAttribute as a refresh/change
Expand Down

0 comments on commit 8248ad6

Please sign in to comment.