From 87522dee366eb56da1de22b74e281129444543db Mon Sep 17 00:00:00 2001 From: halgari Date: Wed, 30 Oct 2024 12:06:50 -0600 Subject: [PATCH] 0.9.95 - fix timestamp regression --- CHANGELOG.md | 3 +++ .../Storage/DatomStore.cs | 2 +- tests/NexusMods.MnemonicDB.Tests/DbTests.cs | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c133448..c7e93b06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/NexusMods.MnemonicDB/Storage/DatomStore.cs b/src/NexusMods.MnemonicDB/Storage/DatomStore.cs index ff44a420..d62fb441 100644 --- a/src/NexusMods.MnemonicDB/Storage/DatomStore.cs +++ b/src/NexusMods.MnemonicDB/Storage/DatomStore.cs @@ -391,7 +391,7 @@ internal void LogDatoms(IWriteBatch batch, TSource datoms, bool advanc /// 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)]); diff --git a/tests/NexusMods.MnemonicDB.Tests/DbTests.cs b/tests/NexusMods.MnemonicDB.Tests/DbTests.cs index f115a74f..718c2c4f 100644 --- a/tests/NexusMods.MnemonicDB.Tests/DbTests.cs +++ b/tests/NexusMods.MnemonicDB.Tests/DbTests.cs @@ -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)recentTimestamp.ObjectValue).Should() + .BeAfter(DateTimeOffset.UtcNow.AddSeconds(-100)) + .And.BeBefore(DateTimeOffset.UtcNow.AddSeconds(100)); + } + [Fact] public async Task CanGetChildEntities() {