Skip to content

Commit

Permalink
0.9.95 - fix timestamp regression
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Oct 30, 2024
1 parent 42fb873 commit 87522de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

### 0.9.95 - 30/10/2024
* Fix a regression with the switch to DateTimeOffset, we now store the correct timestamp in transaction attributes
*
### 0.9.94 - 30/10/2024
* Fix a regression in the GlobalCompare that was boxing an enum (resulting in a lot of allocations)

Expand Down
2 changes: 1 addition & 1 deletion src/NexusMods.MnemonicDB/Storage/DatomStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ internal void LogDatoms<TSource>(IWriteBatch batch, TSource datoms, bool advanc
/// <exception cref="NotImplementedException"></exception>
private void LogTx(IWriteBatch batch)
{
MemoryMarshal.Write(_txScratchSpace.Span, _timeProvider.GetTimestamp());
MemoryMarshal.Write(_txScratchSpace.Span, _timeProvider.GetUtcNow().ToUnixTimeMilliseconds());
var id = EntityId.From(_thisTx.Value);
var keyPrefix = new KeyPrefix(id, AttributeCache.GetAttributeId(MnemonicDB.Abstractions.BuiltInEntities.Transaction.Timestamp.Id), _thisTx, false, ValueTag.Int64);
var datom = new Datom(keyPrefix, _txScratchSpace[..sizeof(long)]);
Expand Down
21 changes: 21 additions & 0 deletions tests/NexusMods.MnemonicDB.Tests/DbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,27 @@ await VerifyTable(updateDatom)
}
}

[Fact]
public async Task TimestampsArentBorked()
{
using var tx = Connection.BeginTransaction();
var loadout = new Loadout.New(tx)
{
Name = "Test Loadout"
};

var result = await tx.Commit();

var recentTimestamp = result.Db.RecentlyAdded
.Resolved(Connection)
.First(d => d.A == Transaction.Timestamp);

recentTimestamp.ObjectValue.Should().BeOfType<DateTimeOffset>();
((DateTimeOffset)recentTimestamp.ObjectValue).Should()
.BeAfter(DateTimeOffset.UtcNow.AddSeconds(-100))
.And.BeBefore(DateTimeOffset.UtcNow.AddSeconds(100));
}

[Fact]
public async Task CanGetChildEntities()
{
Expand Down

0 comments on commit 87522de

Please sign in to comment.